views:

28

answers:

1

Supose you have a command line executable that receives arguments. This executalbe is widechar ready and you want to test if one of this arguments starts with an HYPHEN case in which its an option:

command -o foo

how you could test it inside your code if you don't know the charset been used by the host? Should be not possible to a given console to produce the same HYPHEN representation by another char in the widechar forest? (in such case it would be a wild char :P)

int _tmain(int argc, _TCHAR* argv[])
{
   std::wstring inputFile(argv[1]);
   if(inputFile->c_str() <is an HYPHEN>)
   {
      _tprintf(_T("First argument cannot be an option"));
   }
}
+2  A: 

In your case, Windows will deliver the command line as a UTF-16 string so you shouldn't need to worry about character sets. Just check (inputFile->c_str()[0] == L'-') and you should be good to go. Of course UTF-16 is a variable-length encoding but the hyphen character is represented by a single wide-char value.

Mike Weller