如何读取UNICODE文件?(C ++) [英] How to read UNICODE file ?(C++)
本文介绍了如何读取UNICODE文件?(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想阅读一个歌词文件,所以使用标准的C ++来获取它。但结果是一堆垃圾字符。
I want to read a lyrics file,so use the standard C++ to get it.But the result is a pile of garbage characters.
ifstream in("1.lrc");
string s;
while(getline(in,s)
{
…………
}
in.close();
我怎么能用C ++读取UNICODE文件?
谢谢。
我的英语很差。
How can i read UNICODE file with C++?
Thank you.
My english is very poor.
推荐答案
如果source是Unicode然后你应该使用 wstring
。
If the source is Unicode then you should be using wstring
.
感谢你的帮助。
Thanks for your help.
ifstream fin(strFileName,ios_base::in|ios_base::binary);
size_t index = 2;
wstring ws;
while (!fin.eof())
{
//fin.seekg(index, ios::beg);
wchar_t wch;
fin.read((char *)(&wch), 2);
if (wch == 0x000D)
{
CUser u;
string s;
s=u.WstringToString(ws);
AnaliseString(s);
ws.erase(0, ws.size() + 1);
index += 4; }
else
{
ws.append(1,wch);
index += 2;
}
}
这篇关于如何读取UNICODE文件?(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文