·上一篇:VB SQL Server及Access数据库连接实例
·下一篇:SQL语句Where中使用别名作为判断条件
C++中wchar_t 宽字节流不能写入中文的问题解决
先看程序:
- C/C++ code复制代码
#include "stdafx.h" #include <fstream> int _tmain(int argc, _TCHAR* argv[]) { std::wofstream test(L"Test.Log"); test << L"hello 中文"; return 0; }
UNICODE编译、调试;结果中Test.Log文件的内容只有“hell”没有“中文”。
这是因为C++标准库的国际化设计问题,你需要设置locale。
- C/C++ code复制代码
#include "stdafx.h" #include <fstream> #include <locale> int _tmain(int argc, _TCHAR* argv[]) { std::wofstream test(L"Test.Log"); test.imbue( std::locale("CHS") ); test << L"hello 中文"; return 0; }
再调试,不是有“中文”了?
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论
