Skip to content
Search

Std::locale

lastmod 2018-08-17created 2016-04-136 edits

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;
}

To apply it to a stream, use 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