对于TCHAR或者wchar_t这种Unicode类型字符——宽字符的输出。
对于c有 _tprintf(L"%sn",str);
对于c++有 wcout << str;
#include#include #include using namespace std; //获取环境变量 int main() { //_environ 是系统预定义的,Unicode版本是_wenviron //环境变量是放在电脑的注册表里 char **p =_environ;//环境变量,是一个指向字符串数组的指针 while(*p != NULL) { printf("%sn",*p); p++; } //定位查找环境变量,但只能改变当前进程的环境变量 TCHAR buf[1024]; GetEnvironmentVariable(L"Test", buf, 1024); wcout << buf << endl; //改变环境变量的值 SetEnvironmentVariable(L"Test",L"oK!"); GetEnvironmentVariable(L"Test", buf, 1024); wcout << buf << endl; //如果想知道某个变量代表什么意思 DWORD length = ExpandEnvironmentStrings(L"%ProgramFiles%", NULL, 0); TCHAR *str = new TCHAR[length+1]; ExpandEnvironmentStrings(L"%ProgramFiles%",str,length); wcout << str << endl; _gettchar(); return 0; }
qt的c++工程 _tprintf无法全部输出宽字符字符串,而同样的代码在VS里可以。
qt的c++工程可以使用wcout完成对宽字符串的输出。



