Why does an address value occur when parsing main () arguments?

I am using Visual C ++ with the following code:

int _tmain(int argc, _TCHAR* argv[])
{

    for (int i = 0; i < argc; ++i)
    {
        cout << argv[i] << endl;
    }


    getch();
    return 0;
}

A program with a name MyProgram.exe.

Then I run the program: MyProgram.exe hello world

The program should have printed:

MyProgram.exe
hello 
world

but he didn’t, he printed 3 lines of address values:

005D1170
005D118C
005D1198

Did I do something wrong?

+3
source share
4 answers

You need to use:

std::wcout<<argv[i];

I assume that you included Unicode in your compilation, and when you do this, it _TCHARis defined as wchar_tand therefore you use the version std::wcoutto output a wide char string.

If Unicode is not enabled in the build settings,

std::cout<<argv[i];

, _TCHAR char <<, char.

+6

argv[i] - _TCHAR, std::cout operator << _TCHAR. . A _TCHAR - MSVS ( unicode, , , ).

+3

, _UNICODE. _TCHAR be wchar_t . std::cout ( char*). ( wchar_t*) std::wcout.

+3

cout << argv[i] << endl;

wcout << argv[i] << endl;

Unicode , cout. cout UNICODE.

+1

All Articles