aks
aks

Reputation: 1359

uint8 displays weird characters

I've declared a uint8 variable and when the value in it is printed, I get smiley faces and white spaces. Shouldn't it display integer values?

Upvotes: 7

Views: 6895

Answers (2)

usta
usta

Reputation: 6869

I bet uint8 is a typedef for unsigned char in your system headers. Then std::cout << u will print symbols rather than integer values, where u is of type uint8. Try

std::cout << static_cast< int >( u );

or

std::cout << +u;

to have numeric values printed.

Upvotes: 17

Javert93
Javert93

Reputation: 644

It all depends on how you printing the value out. For cout, try cout << (long unsigned int)var;, and for printf, you can try using the %lu format specifier. However, like usta mentioned, uint8 is likely defined or typedef'd as something else, since that is not an ISO C++ type. There is also the possibility that uint8 is typedef'd to unsigned long int (generic), or unsigned __int64 (MS platform specific), and the MSVC++ compiler is just doing the wrong implicit conversion. Without knowing what uint8 is defined as, it is hard to tell.

Upvotes: 0

Related Questions