为什么getline正在读取我的整个unicode文件
Why getline is reading my entire unicode file
我见过很多线程,但给出的解决方案都不适合我,所以如果有人能提供一些线索,那就太好了我正在读取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是小端序,因此要跳过BOM和imbue utf16,你需要通过发明一种新的转换模式来打击它。
希望它能帮助你。我把写作的一面留给你。
相关文章:
- 在特定 Unicode 路径中创建文件
- 如何存储 unicode 字符并将其输出到文件?
- C++如何通过忽略每行的第一个字符来读取 unicode 文件
- C++:如何将 unicode 字符打印到文本文件
- Linux Ubuntu 中的文件内输出 unicode 符号
- 使用 Imread 打开具有 Unicode 名称的图像文件
- 将 Unicode 字符/字符串写入文件
- 将 Unicode 字符存储在.txt文件中的新行中
- 读取 CSV 文件(UNICODE 编码)C++时出现编码错误
- 无法将 Unicode(希腊语)字符保存到文件中
- 如何在 c++ 中调用 unicode 函数 CreateProcessW 来启动 Windows 可执行文件
- 无法读取使用Unicode的文件(存在)
- 如何将 unicode 文本打印到输出文件?
- 从包含Unicode字符的文件中读取
- 使用C++的可视 Unicode 文件函数
- C/C++ 将编码设置为 UNICODE。如何将'ă'写入文件
- 删除用户 Temp 目录中的文件夹,但也要考虑 unicode 文件夹名称
- 为什么getline正在读取我的整个unicode文件
- 使用std::wifstream读取带有特殊字符的unicode文件
- 如何在c++中读取西里尔字母Unicode文件