I'm working on a problem (Huffman Tree encoding/decoding) and I need to covert and Int to a char.

I was trying to use

char temp = static_cast <char> (index);  //index is an integer

it compiles but if I try to print, it crashes so obviously that idea doesn't work (or at least I am doing it wrong lol)

I know about the itoa function but we are not allowed to use it as it will not work with cygwin.


Make sure it's between 0 and 9 and then add '0' to it. char a; a= '0' + 1 (a = '1')

Maybe I was being vague, I meant I was trying to do something like saving 100 as a char would in turn be translated to 'd'. But it turns out my idea works I was just being goofy and forgot to place a check to keep it from trying to print a non printable character.

ah ok. Yeah, looking back I see what you mean now, the way I read it was you had a single integer digit and were trying to "cast" it to it's character. Apologies then. At least you figured it out.