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

node.js - How do I prevent MongoDB replica set from querying the primary? -

c# - Randomly pick a specific int from a 2D Array -

php - Angularjs http.delete is not working after deploying project on server -