wifstream

Started by
1 comment, last by SiCrane 19 years, 5 months ago
What's the best way to read in unicode text files? I tried to use the wifstream class, but I did not work correctly. I create a unicode text file using notepad, then I loaded it into the MSVC Hexeditor. This looks like this: hexeditor.gif And that's the way I try to load it:

wifstream Stream("extensions.txt");
while(!Stream.eof())
{
  wstring String;
  getline(Stream,String);
  wcout << String <<endl;
}
How can I achieve this task? I think wifstream just reads byte after byte and then converts each single byte into a wchar_t.
Advertisement
I believe the issue is with the codecvt used within the wstream classes for reading text in. Unfortunately, wstreams aren't required to read in 2 byte characters at a time and convert them to a single wide character as you are expecting. This makes them completely useless, at least for me. I believe the rationale is that they didn't want to require a certain byte representation to be used. I would just use binary file I/O to achieve the same thing.

Chalk this up as yet another reason I dislike the standard stream library.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
You might want to try imbuing a null codecvt on your wifstrean object. An example of that process can be found here.

This topic is closed to new replies.

Advertisement