在VC2010环境下, 以下代码无法实现使用CStdioFile向文本文件中写入中文(用notepad.exe查看不到写入的中文)

CStdioFile file;

file.Open(…);

file.WriteString(_T("abc你好"));//只能写入abc

 

解决办法:

使用setlocale语句设定区域

#include <locale>//头文件

CStdioFile file;

file.Open(…);

char* old_locale = _strdup( setlocale(LC_CTYPE,NULL) );

setlocale( LC_CTYPE, "chs" );//设定

file.WriteString(_T("abc你好"));//正常写入

setlocale( LC_CTYPE, old_locale );

free( old_locale );//还原区域设定

相关文章:

  • 2021-07-05
  • 2022-12-23
  • 2021-07-16
  • 2021-07-19
  • 2021-09-10
  • 2022-12-23
  • 2022-01-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
相关资源
相似解决方案