1

我正在尝试使用wifstream将文本文件中的 Unicode 字符读入wchar_t指针数组。这是一个代码片段:

locale::global(std::locale("en_US.UTF-8"));
std::wifstream inputFile("gsmCharacterSet.txt", std::ifstream::binary | std::ifstream::ate);
int length = inputFile.tellg();
inputFile.seekg(0,inputFile.beg);
wchar_t *charArray = new wchar_t[length];
inputFile.read(charArray,length);

它不工作。返回的长度是 252,这是正确的文件大小(以字节为单位)。但是,数组仍然是空的。

以下条件返回true

if ( inputFile.peek() == std::wifstream::traits_type::eof() )
    cout << "File is empty";

我正在使用 g++ 在 Linux 上编译程序。我究竟做错了什么?谢谢您的帮助。

4

0 回答 0