c++ - Why does string sometimes is written in one direction, sometimes in another? -


this code:

byte bytes[] = {0x2e, 0x20, 0x65, 0x00, 0x74, 0x00, 0x61, 0x00, 0x64, 0x00, 0x70, 0x00, 0x75, 0x00, 0x67, 0x00}; std::wstring s; s.resize( 8 ); memcpy( &s[0], bytes, 16 );  _tprintf( _t("key: %s\n"), s.c_str()); messagebox ( 0, s.c_str(), _t(""), 0 ); 

the result in message box gupdate in in console ?etadpug.

i think encoding. 0x2e20 or 0x202e mean something?

your bytes sequence of chars in utf-16 (2-byte-per-char encoding).

it contains reversed string gupdate after rtl override mark (which reverses order of symbols after it).

specifically:

0x2e, 0x20  = u+202e = right-to-left override 0x65, 0x00  = u+0065 = e 0x74, 0x00  = u+0065 = t 0x61, 0x00  = u+0074 = etc. 

note how bytes reversed.

so, message box reverses order of characters, because unicode-aware , sees rtl override mark. regular console output not (actually, is, depends on project settings , functions use io. in case it's non-aware version).


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -