I just wonder simple problem on windows in cmd.exe console program. I write simple one file program in c++ in utf8 encoding:
// utf8 source file encoding
#include <iostream>
#include <iomanip>
int main() {
// compile and run on windows 10 and change code page to utf
// execute from cmd.exe
// WHY first letter 'П' - first time not printed? But after space printed?
std::system("chcp 65001>nul");
const char* utf8 = u8"Привет Мир"; // this will skip first letter with MinGW compiler
const char* utf8s = u8" Привет Мир"; // this will print nice!!! Just add space
std::cout << "cout\n";
std::cout << utf8 << std::endl;
std::cout << utf8s << std::endl;
std::cout << utf8 << std::endl;
std::cout << std::flush;
std::wcout << L"wcout\n";
std::wcout << L"Привет Мир" << std::endl;
std::wcout << L" Привет Мир" << std::endl;
std::wcout << L"Привет Мир" << std::endl;
std::wcout << std::flush;
std::printf("printf\n");
std::printf("%s\n", utf8);
std::printf("%s\n", utf8s);
std::printf("wprintf\n");
std::wprintf(L"Привет Мир\n");
std::wprintf(L" Привет Мир\n");
std::wprintf(L"Привет Мир\n");
std::fflush(stdout);
std::system("pause");
return 0;
}
Output form git-bash.exe This programs outputs nice on windows 10 in git-bash.exe but in cmd.exe with Lucida Console font and even with chcp 65001
still not printing first letter of Russian "Hello World" -> "Привет Мир". I try compile this code with MinGW 7.1 and with MSVC2017 but nothing changed. I know that rustc.exe(Rust Lang compiler) produce binary files that works in cmd.exe and in git-bash.exe too with utf8 text printing. How to do it in C++ program on windows? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire