标签:style os ar 文件 问题 代码 sp on line
在windows系统下将一个含有中文的字符串缓存写入指定路径下的文本文件中,假如采用_wfopen(),fwprintf()方式写入,务必在调用fwprintf()之前加上_wsetlocale(0, L"chs");这句,否则系统不支持,写出来的文本文件会是乱码或者问号字串。
示例代码如下:
FILE* fp = _wfopen(L"Data.txt",L"a+");
if(fp == NULL)
{
return false;
}
_wsetlocale(0,L"chs");//务必加上否则生成的文本是问号字符串
fwprintf(fp,L"%s\n",L"中文字符串写入文本");
fclose(fp);
关于fwprintf(fp,L"%s\n",str_chs)的UNICODE问题。
标签:style os ar 文件 问题 代码 sp on line
原文地址:http://my.oschina.net/u/923534/blog/308477