为什么在解析main()参数时获取地址值?

ipk*_*iss 3 c++ program-entry-point command-line-arguments

我使用Visual C++与以下代码:

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

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


    getch();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

该计划命名MyProgram.exe.

然后我运行程序:MyProgram.exe hello world

该程序应该打印:

MyProgram.exe
hello 
world
Run Code Online (Sandbox Code Playgroud)

但它没有,它打印了3行地址值:

005D1170
005D118C
005D1198
Run Code Online (Sandbox Code Playgroud)

我做错什么了吗?

Alo*_*ave 6

你需要使用:

std::wcout<<argv[i];
Run Code Online (Sandbox Code Playgroud)

我猜你已经在你的编译中启用了Unicode,当你这样做时,_TCHAR定义为wchar_t,因此你使用该std::wcout版本输出宽字符串.

如果您没有在构建选项中启用Unicode,那么

std::cout<<argv[i];
Run Code Online (Sandbox Code Playgroud)

会工作得很好,因为那时_TCHAR被定义为char并且有一个<<带有char参数的运算符的重载版本.