重拾C++的编程之路:
先来一个hello world(这是生成的window应用程序)
#include#include #include using namespace std;int main(){MessageBox(NULL,"Hello world","Information",0);return 0;}
若弹出提示无XXX.exe文件,的项目->属性->常规->设置为不使用UNICODE,发现设置为多字节字符集也可以,,,,,
,,,,,
现在生成一个控制台应用程序
#includeint main(){ char sz[128]={0}; strcpy_s(sz,"Hello world!"); std::cout< <
由于控制台程序一闪就关了,所以加一句:
system("pause");
再有如果使用
strcpy(sz,"Hello world!");
报错:warning C4996: 'strcpy': This function or variable may be unsafe. Consider using
strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.故:改为
strcpy_s(sz,"Hello world!");
strcat 也一样
stricmp的加强函数是 _stricmp()
再试试这种方式 用两个宏TEXT和_T(通过tchar.h) 不用调节字符为多字节型时:
#include#include #include using namespace std; int main(){ MessageBox(NULL,TEXT("information"),TEXT("Information"),0); MessageBox(NULL,_T("你好HelloWorld"),_T("Information"),0); system("pause"); return 0;}
_T会被替换为L##x,##是个预编译命令,目的是将L和x贴在一起,
_T("pstr")被替换成 L##Lpstr==============>因此_T只能直接编译直接的字符串。