1
votes

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);
1
Extended ASCII does not exist. State your desired encoding and also set your console to use said encoding. - Lightness Races in Orbit
If we want to call it extended ascii then we can. So there! - David Heffernan
@DavidHeffernan: the problem is, there are many "extended ASCII" encodings. Refer to a similar question with better answers. - André Caron
What you have in your link is codepage 437. I recommend reading this article, by the co-creator of this website, in order to slightly increase your knowledge on character encodings. - Benjamin Lindley
Let's say I want to use UTF-8 encoding and print characters in the console. How do I do that? - Julián Muriel Tejo Rodríguez

1 Answers

2
votes

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.