Visual Studio C++ 控制台打印 CString

Visual Studio C++ 控制台打印 CString

//不含中文的情况下

CString str1 = _T("hello world.");
wprintf(_T("%s\r\n"), str1.GetBuffer()); str1.ReleaseBuffer();
wcout << str1.GetBuffer() << endl; str1.ReleaseBuffer();
wcout << str1.GetString() << endl;
wcout << (LPCTSTR)str1 << endl;

hello world.
hello world.
hello world.
hello world.
请按任意键继续. . .

//含中文的情况下
wcout.imbue(std::locale("chs"));
CString str1 = _T("hello world. 含中文的情况下");
wprintf(_T("%s\r\n"), str1.GetBuffer()); str1.ReleaseBuffer();
wcout << str1.GetBuffer() << endl; str1.ReleaseBuffer();
wcout << str1.GetString() << endl;
wcout << (LPCTSTR)str1 << endl;

hello world. ???????
hello world. 含中文的情况下
hello world. 含中文的情况下
hello world. 含中文的情况下
请按任意键继续. . .

猜你喜欢

转载自www.cnblogs.com/dailycode/p/11953986.html