C++, command line args not being parsed properly

c++, command-line-arguments, parsing

Solution

Your Visual C++ project is set to Unicode, and your main function is called _tmain. This means that Windows invokes your function and passes you Unicode strings, but you're treating them as ANSI strings by using the char* type. Since the second byte of the first Unicode character is null, this appears as an ANSI string with one character.

Problem

I have a program: ``` int _tmain(int argc, char* argv[]) { std::cout << "STARTING" << std::endl; std::cout << "Num inputs: " << argc << std::endl; for(int i = 0; i < argc; i++) std::cout << argv[i] << std::endl; ``` that I expect to print out all the command line arguments. However, the output is this: ./Test.exe hello world STARTING Num inputs: 3 . h w It appears that it's only looking at the first char in each argument and not the entire char* till termination character. Anyone have any thoughts? Additional Notes: Creating it through VS2008, and I am essentially copying and pasting an example on the internet that should work. I have run the program in bash, powershell, and cmd.

Original source

Related problems