Reading in Russian characters (Unicode) using a basic_ifstream<wchar_t>
- by Mark
Is this even possible? I've been trying to read a simple file that contains Russian, and it's clearly not working.
I've called file.imbue(loc) (and at this point, loc is correct, Russian_Russia.1251).
And buf is of type basic_string<wchar_t>
The reason I'm using basic_ifstream<wchar_t> is because this is a template (so technically, basic_ifstream<T>, but in this case, T=wchar_t).
This all works perfectly with english characters...
while (file >> ch)
{
if(isalnum(ch, loc))
{
buf += ch;
}
else if(!buf.empty())
{
// Do stuff with buf.
buf.clear();
}
}
I don't see why I'm getting garbage when reading Russian characters. (for example, if the file contains ??? ??? ???, I get "??E", 5(square), K(square), etc...