1

I'm trying to read Unicode characters from a text file into a wchar_t pointer array, using wifstream. Here is a code snippet:

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);

It's not working. The length returned is 252 which is the correct file size in bytes. However, the array remains empty.

The following condition returns true:

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

I'm compiling the program on Linux using g++. What am I doing wrong? Thanks for the help.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
yogur
  • 810
  • 10
  • 19

0 Answers0