c++ – Krakozyabry at the beginning of the line in the console

Question:

Put the utf-8 encoding:

SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);

I display the text in the stream:

cout << "Введите первое число: a = ";

And the console gives me this:

��ведите первое число: a =

I tried to search for information in the tyrnet, unfortunately, I could not find anything, perhaps I was looking for it incorrectly. Please help me solve the problem.

Answer:

This is due to the fact that the low-level WinApi functions for outputting strings to the console in UTF-8 expect a complete string. Functions like puts will print your string correctly. But the output via basic_ostream<char>::operator<<(char*) probably for a string

"Введите первое число: a = "

calls winapi first with the first byte of the double-byte character В , then the second and the rest of the line, which is displayed as:

��ведите первое число: a =
Scroll to Top