Answer the question
In order to leave comments, you need to log in
How to make your own function for converting from UTF8 to ANSI?
I always created sources in win1251, and used setlocale(LC_ALL, ".866")
wcout to output Cyrillic. Then I decided that it was not kosher and started creating sources in utf8. Everything was fine until I again ran into the output of the Cyrillic alphabet.
The old version with setlocale no longer worked and I decided to write my own function for converting Cyrillic characters into a console-readable form.
void SetRusChar(char &symbol)
{
if(!symbol)
{
return;
}
/// "Разрыв" кириллицы в таблице символов ANSI
const int min=-128;
const int max=-96;
if(symbol>min&&symbol<max)
{
const int addOffset=-112;
symbol-=addOffset;
}
const int offset=16;
symbol-=offset;
}
std::string GetRusString(std::string line)
{
const char bigWaste=-48;
const char littleWaste=-47;
for(std::string::iterator i=line.begin(); i<line.end(); ++i)
{
if(*i==bigWaste||*i==littleWaste)
{
line.erase(i);
}
SetRusChar(*i);
}
return line;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question