In your windows system's code page, á is a single byte character, i.e. every char
in the string
is indeed a character. So you can just loop and print them.
On Linux, á is represented as the multibyte (2 bytes to be exact) utf-8 character 'C3 A1'. This means that in your string
, the á actually consists of two char
s, and printing those (or handling them in any way) separately yields nonsense. This will never happen with ASCII characters because the utf-8 representation of every ASCII character fits in a single byte.
Unfortunately, utf-8 is not really supported by C++ standard facilities. As long as you only handle the whole string
and neither access individual char
s from it nor assume the length of the string
equals the number of actual characters in the string
, std::string
will most likely do fine.
If you need more utf-8 support, look for a good library that implements what you need.
You might also want to read this for a more detailed discussion on different character sets on different systems and advice regarding string
vs. wstring
.
Also have a look at this for information on how to handle different character encodings portably.