Say "The character is unprintable" and then display its ASCII value. The unprintable characters are those with ASCII value less than 32.
Your program need process only those characters with ASCII values in the range 0-127.
That's OK. A remark in your documentation will suffice.
You probably just need to use the escape sequence \'. If that doesn't work, you can use the ASCII value of ' by converting it to a character.
Hmmm. The static_cast<int> operator seems to work fine on my machine. But it is possible that your installation of MSVC++ does not support it, as it is a relatively recent addition to the language. In this case, you should be able to get by with the earlier, simpler notation: int(). E.g., cout << int('a'); should print out 97.
The problem is that the >> operator ignores leading
whitespace (blanks, tabs, and newlines).
If you want to treat all characters the same, and not ignore whitespace,
you have to use the "get()" member function instead of the
>> operator. E.g.,
char myChar;
cin.get( myChar );
I overlooked this issue in the specification, and I don't believe
the TAs covered it in discussion, so we won't deduct points for
programs that can't handle whitespace and unprintable characters
correctly. We will discuss the "get()" function in more
detail later in the quarter. Sorry for this oversight!
Examples of an unprintable character are the escape key (ESC) and
the CTRL sequences (CTRL-A, CTRL-B, etc.). Some of these (e.g., ESC)
will also not be readable with >>. If you use the "get()"
member function, you should be able to read all of these without any problem.
A character not enclosed in single apostrophes is interpreted by the compiler as an identifier (a programmer-defined name). To specify a character constant, enclose the character in apostrophes: ch = 'z';
You can print out st this way: