c++ - INTtoCHAR function couts wrong value -
here function looks like:
signed char inttochar(int int) { signed char char = (signed char)int; return char; } int chartoint(signed char char) { int int = (int)char; return int; } it works assigns int value char, when want cout char gives me weired signs. compiles without errors.
my testing code is:
int main() { int x = 5; signed char after; char compare = '5'; after = inttochar(5); if(after == 5) { std::cout << "after:" << after << "/ compare: " << compare << std::endl; } return 0; } after indeed 5 doesn't print 5. ideas?
adding above answer using unary operator +, there way well: typecasting.
std::cout << "after:" << (int)after << "/ compare: " << compare << std::endl;
Comments
Post a Comment