c++ - byte representation of ASCII symbols in std::wstring with different locales -


windows c++ app. have string contain ascii symbols: std::wstring(l"abcdeabcde ... other ascii symbol"). note std::wstring uses wchar_t.

question - byte representation of string depends on localization settings, or else? can assume if receive such string (for example, windowsapi) while app running bytes same on pc?

in general, characters (not escape sequence) wchar_t , wstring have use same codes ascii (just extended 2 bytes). not sure codes less 32 , of course codes greater 128 can has different meaning (as in ascii) in moment of output, avoid problem on output set particular locale explicitly, e.g.:

  locale("en_us.utf-8") 

for standard output

  wcout.imbue(locale("en_us.utf-8"));  

update:

i found 1 more suggestion adding

  std::ios_base::sync_with_stdio(false); 

before setting localization imbue

see details on how can use std::imbue set locale std::wcout?


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo