Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7620
  • 博文数量: 4
  • 博客积分: 186
  • 博客等级: 入伍新兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-30 10:41
文章分类
文章存档

2013年(1)

2010年(3)

我的朋友
最近访客

分类: C/C++

2010-05-14 17:00:13

问题描述:
    使用fstream打开文件后,若输出字符中含有中文,中文字符后面的内容就输出不到文件中。

问题解决:
    在需要支持中文时设置本地语言区域码,例如:

wofstream        m_FileStream;        // 文件流。

m_FileStream.open(m_strFilePath.c_str(), ios_base::out | ios::_Noreplace | ios::trunc );
std::locale oldLocale = m_FileStream.imbue(std::locale(std::locale("chs"), "", LC_CTYPE));

m_FileStream << L"file中文测试\n";

m_FileStream.imbue(oldLocale);
m_FileStream.close();


举一反三:
    其它stream也有类似情况,如std::in、std::out、std::iostream等。

参考:
http://blog.chinaunix.net/u2/61062/showart_2118486.html
阅读(725) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~