leo00 发表于 2014-7-25 09:07:30

vc++ 将数据写入txt文件,换行问题

CFile file ;
CString strFileName = _T("F:\\1.txt");
file.Open(strFileName,CFile::modeCreate|CFile::modeReadWrite);
CString str, strTmp;
for (int n = 0; n < 20; n++)
{
strTmp.Format(_T("%d\r\n"),n);
file.Write(strTmp,strTmp.GetLength());
}
file.Close();

(使用 Unicode 字符集)
我想实现换行,运行结果没有换行

hong5499999 发表于 2014-7-25 09:07:42

你犯了个弱智错误,unicode前面两字节应该写上FF FE
否则会以ascii方式打开。。所以就错了,
比如
FF FE 30 00 31 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00 0D 0A
就是
”0123456789/r/n“
只是需要在文件开头写上FF FE,若续写文件就不需要重复再写

846530637 发表于 2014-7-25 12:41:18

:victory:顶起来,,,
页: [1]
查看完整版本: vc++ 将数据写入txt文件,换行问题