为啥只得到了一个字符
为什么只得到了一个字符
为什么生成test.exe后运行,参数2取得的值是一个字符?
比如:
test.exe "abcdefg"
输出的是:"a" ,我想输出的是参数2(qrText2)的值: "abcdefg",而qrText输出的是所有字符"http://www.test.org/index.htm" ,新手学C++,不解。
------解决方案--------------------
_tmain 参数是宽字符, 把_tmain改成main
------解决方案--------------------
宽字符使用wcout
------解决方案--------------------
纯C++的代码练习最好不要用_tmain作为主函数,main()就好
------解决方案--------------------
using gcc in linux, no such issue.
output:
http://www.test.org/index.htm
abcdefg
#include <iostream>
#include "stdafx.h"
#include <string.h>
#include <errno.h>
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <wchar.h>
int _tmain(int argc, char* argv[])
{
char* qrText="http://www.test.org/index.htm";
char* qrText2="";
if (argc != 2)
{
printf("参数错误,文件名\n");
exit(EXIT_FAILURE);
}else{
qrText2=argv[1];
cout<<qrText<<endl;
cout<<qrText2<<endl;
}
return 0;
}
为什么生成test.exe后运行,参数2取得的值是一个字符?
比如:
test.exe "abcdefg"
输出的是:"a" ,我想输出的是参数2(qrText2)的值: "abcdefg",而qrText输出的是所有字符"http://www.test.org/index.htm" ,新手学C++,不解。
------解决方案--------------------
_tmain 参数是宽字符, 把_tmain改成main
------解决方案--------------------
宽字符使用wcout
------解决方案--------------------
纯C++的代码练习最好不要用_tmain作为主函数,main()就好
------解决方案--------------------
using gcc in linux, no such issue.
output:
http://www.test.org/index.htm
abcdefg