为什么argc argv用cout输出的是地址?解决方法
为什么argc argv用cout输出的是地址?
这是代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
while (argc)
{
cout<<argv[--argc]<<endl;
}
system("pause");
return 0;
}
命令行下输入:con-t1.exe a b c
这是结果:
003F519A
003F5196
003F5192
003F517C
请按任意键继续. . .
为什么是地址呢?不是应该是字符串吗?
------解决方案--------------------
输出*argv[--argc]就能输出字符串了,那是个指向数组的指针
------解决方案--------------------
将项目属性改为使用多字节字符集即可,不要使用unicode。
------解决方案--------------------
wcout
------解决方案--------------------
这是代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
while (argc)
{
cout<<argv[--argc]<<endl;
}
system("pause");
return 0;
}
命令行下输入:con-t1.exe a b c
这是结果:
003F519A
003F5196
003F5192
003F517C
请按任意键继续. . .
为什么是地址呢?不是应该是字符串吗?
------解决方案--------------------
输出*argv[--argc]就能输出字符串了,那是个指向数组的指针
------解决方案--------------------
将项目属性改为使用多字节字符集即可,不要使用unicode。
------解决方案--------------------
wcout
------解决方案--------------------
- C/C++ code
#include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { while (argc) { cout<< *argv[--argc] <<endl; /* argv[--argc] 为数组指针,直接输出肯定是地址 */ } system("pause"); return 0; }
------解决方案--------------------
cout<< argv[--argc] <<endl;