D
D
Daniel2018-09-11 23:40:07
C++ / C#
Daniel, 2018-09-11 23:40:07

Compiling on the c++ command line, krakkrozyabry instead of russian letters?

I compile in cmd with encoding 1251.
"g++ main.cpp -o main.o"
"main.o"

#include <cstdlib>
#include <iostream>
#include <stdio.h>
using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    setlocale(LC_ALL, "Russian");// 10ки вариантов испробовал
    char *name;
    cout<< "Введите ваше имя "; // Введе ваше РёРјСЏ hjh
   
    
    //system("pause");
    return 0;
}

Conclusion: Р'веде ваше РёРјСЏ hjh

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniel Demidko, 2018-09-12
@DanielDemidko

First, it's best to have all source code files in Unicode (utf16). So all Russian (and other) letters will survive the compilation normally.
Secondly, to work with such strings in the standard library there are classes wcout, wstring and so on, and use them.
What is the problem with the setlocale function? The fact that she makes the output to the console correct, and Russian will be read from the console like krakozyabry.
Here is the correct way:

// Кодировка Unicode
#include <iostream>
#include <string>

int main() {
    // Устанавливаем кодовую страницу как у пользователя на компьютере
    std::locale::global(std:: locale(".OCP"));
     // Строки с юникодом должны начинаться с префикса L
    std::wcout << L"Русский текст в консоли";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question