Extended Ascii characters in Code::Blocks C++

Julián Muriel Tejo Rodríguez picture Julián Muriel Tejo Rodríguez · Feb 8, 2012 · Viewed 9.6k times · Source

I'm trying to use extended Ascii codes in a console application using C++ and Code::Blocks (character codes greater than 128). http://www.asciitable.com/ The console shows a question mark inside a diamond.

I tried so far:

char myChar = 200;
cout << myChar;

cout << static_cast<char>(200);

Answer

EvilTeach picture EvilTeach · Feb 8, 2012

char can't hold the whole character set

use unsigned char instead.

unsigned char myChar = 200;
cout << myChar << endl;

a char is generally a signed char. it can hold values from -128 to 127. ASCII fits nicely in 0 to 127, so char is reasonable when working with ASCII.

For the non-ASCII characters 128 to 255, you need something bigger. unsigned char can store values from 0 to 255. That covers the whole character set. It's just what you need.

There are other things to research. You can read about unicode. But unsigned char should get you around your current issue.