简体   繁体   中英

C++ setlocale for any region

I've written a little program for testing purposes because when using cout, the German letters ü ö ä ß were not displayed as they should but rather rubbish was given out on the console. However, using these lines

#include <iostream>
#include <locale>

using namespace std;

int main()
{
    setlocale(LC_ALL, "German");
    cout << "üüü ööö äää ßßß" << '\n';
    system("pause");
    return 0;
}

have solved this problem, at least as far as the German letters go. When I tried the same for Russian, ie

#include <iostream>
#include <locale>

using namespace std;

int main()
{
    setlocale(LC_ALL, "RUSSIAN");
    cout << "Кирилица" << '\n';
    system("pause");
    return 0;
}

this doesn't work anymore. What is going wrong here? Am I missing something about the setlocale function? My goal is to adapt the respective program to the writing system that is used, for example Cyrillic like aboe or Chinese or whatever.

FOR GERMAN -> std::setlocale(LC_ALL, "de_DE");
FOR RUSSIAN -> std::setlocale(LC_ALL, "rus");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM