使用cstdiofile在vs2010中无法写入中文的问题在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 );//还原区域设定 分类: VC |
|