为什么getline正在读取我的整个unicode文件

Why getline is reading my entire unicode file

本文关键字:unicode 文件 我的 读取 getline 为什么      更新时间:2023-10-16

我见过很多线程,但给出的解决方案都不适合我,所以如果有人能提供一些线索,那就太好了我正在读取unicode文件,并使用getline尝试逐行扫描,但它会扫描整个文件,因为对象是wstring,所以不允许我在getline中放置delimeter。只问了我装不下熟食店的wchar_t。(\0不工作,因为我在二进制模式下阅读)所以下面是代码片段平台:Windows、Visual Studio 2010Unicode编码:UTF16

wifstream fin("profiles1.prd", ios_base::binary);  //open a file
wofstream fout("DXout.txt",ios_base::binary);  // this dumps the parsing ouput
fin.imbue(std::locale(fin.getloc(),new std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header>));
fout.imbue(std::locale(fin.getloc(),new std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header>));
wstring stream;
getline(fin,stream);

我希望这就是您想要的:

fin.imbue(std::locale(fin.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff,
        std::codecvt_mode(std::little_endian|std::consume_header)>);

Windows是小端序,因此要跳过BOMimbue utf16,你需要通过发明一种新的转换模式来打击它。

希望它能帮助你。我把写作的一面留给你。