Reading in Russian characters (Unicode) using a basic_ifstream<wchar_t>

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-03-17T16:57:08Z Indexed on 2010/03/17 17:11 UTC
Read the original article Hit count: 361

Filed under:
|
|

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...

© Stack Overflow or respective owner

Related posts about c++

Related posts about locale