Strings with special characters in foreign language

Aug 11, 2010 at 9:32pm
How can I get the computer to cout in a foreign language such as spanish with ñ or german with ö, ä, ü and ß? if I cout these characters in a string, they r all fcked up. and instead have to actually pass the ascii character value, such as 132 for ä, or have a const char a_umlaut = 132.

so I can do something like this:

1
2
3
4

const char a_umlaut = 132;
cout << "H" << a_umlaut << "tte";


to cout the german word for 'had'
but not like this:

 
cout << "Hätte";


what gives? I find this incredibly anoying. Is it c++ in general or just codeblocks?
Aug 11, 2010 at 10:25pm
It's your terminal emulator.
If you are using cmd to display stdout, you'll have to set up the right code page
Aug 11, 2010 at 10:27pm
¿and how do I do that?
Aug 11, 2010 at 10:57pm
But if I do this char c = 'ñ' gcc yelds
warning: multi-character character constant
and c gets 177 instead of 241. It seems to be system dependent so everything after 127 converts to garbage
Aug 12, 2010 at 10:54am
That depends on the encoding of your source files
Everything after 127 is not ASCII
Last edited on Aug 12, 2010 at 10:55am
Aug 12, 2010 at 5:46pm
could I define a macro (somehow) that would override the system whenever I type alt+132 it would instead of simply typing ä it would type " << a_umlaut << " ? ?
Aug 12, 2010 at 5:54pm
Maybe, but wouldn't it be easier to just type that, instead? Or you can use '\x84' or '\204'.

std::cout doesn't behave very well with non-ASCII. The results are heavily configuration-dependent.
Aug 12, 2010 at 6:19pm
Gee, why didn't I think of that?
Topic archived. No new replies allowed.