阅读Unicode文件C ++ [英] Read Unicode files C++
问题描述
我有一个简单的问题要问。我有一个UTF 16文本文件读取,以FFFE开始。什么是C ++工具来处理这种文件?我只是想读它,过滤一些行,并显示结果。
I have a simple question to ask. I have a UTF 16 text file to read wich starts with FFFE. What are the C++ tools to deal with this kind of file? I just want to read it, filter some lines, and display the result.
看起来很简单,但我只是在使用普通的ascci文件的经验,我很匆忙。我使用VS C ++,但我不想使用托管C ++。
It looks simple, but I just have experience in work with plain ascci files and I'm in the hurry. I'm using VS C++, but I'm not want to work with managed C++.
注意
这里给一个非常简单的例子
Here a put a very simple example
wifstream file;
file.open("C:\\appLog.txt", ios::in);
wchar_t buffer[2048];
file.seekg(2);
file.getline(buffer, bSize-1);
wprintf(L"%s\n", buffer);
file.close();
推荐答案
您可以使用 fgetws ,它读取16位字符。您的文件是小端,字节顺序。由于x86机器也是little-endian,你应该能够处理这个文件没有太多的麻烦。当您想要输出时,请使用 fwprintf 。
You can use fgetws, which reads 16-bit characters. Your file is in little-endian,byte order. Since x86 machines are also little-endian you should be able to handle the file without much trouble. When you want to do output, use fwprintf.
此外,我同意更多的信息可能是有用的。例如,您可能正在使用一个抽象出这些的库。
Also, I agree more information could be useful. For instance, you may be using a library that abstracts away some of this.
这篇关于阅读Unicode文件C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!