Worked on Linux , there were no problems with encodings at all. It was necessary now to work on Windows .

Everything seems to be fine, but there were no Russian symbols, only krakozyabry. Changed to others when:

SetConsoleCP(1251); SetConsoleOutputCP(1251); setlocale(LC_ALL, "Russian"); 

Dug in the registry, changed the font of the console, in general, all that is adequate in Google . After I decided to accidentally change SetConsoleCP(1251); at SetConsoleCP(CP_UTF8); (of course, and SetConsoleOutputCP(CP_UTF8); ).

There was a lot of joy, the native language in the console. But it took a couple of days and now you need to enter more Russian, but the program immediately falls. Judging by the debugger, the string is simply empty.

How can I fix this?

  • rephrase the task, a little is not clear what you are having, well, and see the code. - Alex.B
  • and what does reading happen with the console and in which variable? - maint
  • 2
    not in char to read, but in wchar_t. - maint
  • 2
    because the console specifies UTF-8, and this is a 2-byte encoding - maint
  • 3
    See this answer. There, in general, there is everything so that you can make a working decision. - ixSci

2 answers 2

Check the encoding of the compiled * .cpp files, they should be in the encoding in which you display the text.

    I think you can only answer the code:

     #include "stdafx.h" #include <iostream> #include <Windows.h> using namespace std; int main(int argc, char* argv[]) { SetConsoleCP(1251);// установка кодовой страницы win-cp 1251 в поток ввода SetConsoleOutputCP(1251); // установка кодовой страницы win-cp 1251 в поток вывода char string[20]; cin >> string; // вводим строку, используя Кириллицу cout << "\nвывод: "<< string << endl; // ввывод строки system("pause"); return 0; } 

    source link

    Well, I advise you in the console settings to change the font on the luicida console plus use the cp1251 encoding of the file format with the source code (since this is Windows)

    enter image description here