Casting would be the simple way of doing it. In C, casting looks like this:
(char)x
In C++, you can do the above or use static_cast which is the preferred method:
static_cast<char>(x)
This is uglier and takes more text, but it is safer (more type checking at compile time) and it is good to make a habit of it. Once you cast the int to a char, it will be treated as a char for all operations. Of course, it will be converted implicitly when assigning it to a char and casting will not be needed.
modified on Thursday, March 4, 2010 10:51 PM