Mona04
Mona04

Reputation: 11

Why the function wsetlocale() is needed for unicode encoding?

I learned that Unicode can distinguish many characters used for other languages such as Chinese. Then if we decide the encoding, Utf-16 for example, setting locale is not needed I think. But actually it is not. _wsetlocale() is needed even for Unicode. I wonder why.

_wsetlocale(LC_ALL, L"korean"); 
wchar_t a = L'개';
wcout << a << endl;

Like this. I set Character Set not MBCS but Unicode. Why I have to set locale for unicode?

Upvotes: 1

Views: 597

Answers (1)

selbie
selbie

Reputation: 104464

Primary reason is for doing case insensitive string comparisons with such library functions as wcscasecmp. Additionally, some strings may be evaluated differently with the strcoll and wcscoll library functions than with the traditional strcmp and wcscmp functions. More details at this answer here.

For more details on how the locale influences the c and c++ runtime, consult the man page for setlocale.

Upvotes: 1

Related Questions