C/C++读取中文文本,对字符集有深入研究的高手进
不知怎么弄的,本人将一个中文文本的格式弄乱了,用系统自带的文本工具打开没问题,可在C++中读取时就成乱码了。
被我弄乱的文本文件可在此下载 textTest.rar
其中有两个文件index.txt 为混乱文件;index_good.txt为正常文件。其内容都为"一二三",可大小分别为16B,10B。文件都为UTF-8编码。
C++代码如下
ifstream reader;//locale oldLocale=reader.imbue(locale(locale("chs"),"",LC_CTYPE)); //这里加入中文支持也不行reader.open("d:\\index.txt");char chs[300];reader.getline(chs,300);
CStdioFile file; file.Open("D:\\index.txt",CFile::modeRead); CString str; file.ReadString(str);