This question has already been answered:

When you type in if conditions in Russian, the program does not display the code further.

cout << "Выбери действие:\nсложение/вычитание/умножение/деление/выход\n\n"; cin >> menu; cout << "\n------------------------------------\n"; if (menu == "сложение") { cout << "Первое число:\n\n"; cin >> uix; cout << "\nВторое число:\n\n"; cin >> uiy; cout << "\nПолученное число: " << uix + uiy << endl; 

but if you replace it with English:

 if (menu == "sometext") 

the program displays what you need. How to fix it?

Reported as a duplicate member by VladD c ++ 8 Feb '17 at 22:23 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Most likely uix + uiy you need to convert to a string. - nick_n_a
  • nick_n_a, no, I'm talking about a condition in if. - FoxGo
  • What do you really have in the menu at this moment? - VladD

3 answers 3

Coding mismatch. If you are in Windows - my advice: just work in 866 encoding, respectively, by typing in it the program code itself.

The fact is that programs are usually in 1251 encoding Windows, and the console in 866 encoding.

Another option is to try running the command chcp 1251 before starting the console. For example, the first line after int main() - system("chcp 1251") ...

Here's another - see, for example, here:

Russian language in the console

Cyrillic I / O in the Windows console

  • Well, uh, 866 is terrible because (1) most Windows applications (code editors) do not know it, and (2) it is not good at related languages ​​(Ukrainian / Belarusian), and (3) English diacritics are not at all ( café, crème brûlée, El Niño, naïveté, etc.) Do not drag the vehicle in the past century! - VladD
  • @VladD Well, I myself am from the last century :), and if I really need Russian in the console, I prefer this method. Of course, I do not impose. So to say, as a PS - but in general is to think of it - to use two different encodings at the same time ... - Harry
  • Windows has one Cyrillic encoding - CP1251. The console uses the old CP866 encoding for compatibility with the past century, but no Windows user uses the console. - VladD
  • @VladD Then where is the question of the vehicle from? :) Here at least one person is already there ... - Harry
  • TC is not a user, TC is a programmer. Users do not use the console :) And programmers should suffer for making it more convenient for users :-D - VladD

This example works. Encoding of the .cpp file, i.e. and Cyrillic strings - 866 (OEM Russian)

 #include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main(int argc, char *argv[]) { string menu; int uix, uiy; cout << cout << "Выбери действие:\nсложение/вычитание/умножение/деление/выход\n\n"; cin >> menu; cout << "\n------------------------------------\n"; if (menu == "сложение") { cout << "Первое число:\n\n"; cin >> uix; cout << "\nВторое число:\n\n"; cin >> uiy; cout << "\nПолученное число: " << uix + uiy << endl; } return 0; } 

    Create a new file in your project, copy this content there , then above your main function write down:

      void SetConsole (const wchar_t * pszTitle = NULL, BOOL bFullScreen = FALSE); 

    and in main before calling the I / O objects, call this function like this:

      SetConsole (L "Window Title", TRUE); 

    In the call, the first argument is a string of double-byte characters (the constant begins with 'L' ), which will be displayed in the console header, and the second argument, if TRUE , will expand the console to its maximum size.

    The problem of entering the Cyrillic alphabet is solved by installing the code page 1251 and replacing the font with the Lucida Console . The font can also be manually changed.

    Or open the project Visual Studio 2015 , everything works as it should - Cyrillic in the console on input and output.