Skip to content

Std::locale

The locale facility includes internationalization support for character classification and string collation, numeric, monetary, and date/time formatting and parsing, and message retrieval. Locale settings control the behavior of stream I/O, regular expression library, and other components of the C++ standard library.

Global setting

#include <locale>
int main(void)
{
     std::locale::global(std::locale("ko_KR.UTF-8")); // 맨 처음 한번 실행
     return 0;
}

스트림에 적용할 경우 imbue를 사용하면 된다.

std::wcout.imbue(std::locale("kor"));
std::wcin.imbue(std::locale("kor"));

Returns the name of the locale

#include <locale>
#include <iostream>
#include <string>

int main()
{
    std::locale loc(std::locale(), new std::ctype<char>);
    std::cout << "The default locale is " << std::locale().name() << '\n'
              << "The user's locale is " << std::locale("").name() << '\n'
              << "A nameless locale is " << loc.name() << '\n';
}

See also

Favorite site