Is ti_hour a char type (char, unsigned char or signed char)? The problem is that C++ doesn't have different types for characters and integers. char is actually an integer type of size 1 byte, but char is often used to store characters so the << overload for char will assume you want to print a character. By casting the variable to an int you get the int overload of << which will print the value as an integer.