用户登录  |  用户注册
首 页源码下载网络学院最新源码源码排行屏蔽广告
当前位置:新兴网络 > 网络学院 > 编程开发 > C/C++

C++中wchar_t 宽字节流不能写入中文的问题解决

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2010-05-24 15:10:54

先看程序:

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;
}

再调试,不是有“中文”了?

Tags:C++ wchar_t 宽字节流

作者:佚名
  • 好的评价 如果您觉得此文章好,就请您
      0%(0)
  • 差的评价 如果您觉得此文章差,就请您
      0%(0)

网络学院评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论