From: Dave on
The following compiles and runs on Linux with gcc 4.0.1.

#include <iostream>
#include <stdint.h>
//#include <inttypes.h>

using namespace std;

int main()
{
uint16_t i16 = 16;
uint8_t i8 = 8;
unsigned char c = 'C';

cout << endl << "uint16_t i16 = " << i16 << endl;
cout << endl << "uint8_t i8 = " << i8 << endl;
cout << endl << "char c = " << c << endl;

return 0;
}

The output is

uint16_t i16 = 16

uint8_t i8 =

char c = C


Why is the value for the uint8_t i8 not output? Works fine if I change it
to a uint16_t.


TIA,

~Dave~
From: Ulrich Eckhardt on
Dave wrote:
> uint16_t i16 = 16;
> uint8_t i8 = 8;
> unsigned char c = 'C';
>
> cout << endl << "uint16_t i16 = " << i16 << endl;
> cout << endl << "uint8_t i8 = " << i8 << endl;
> cout << endl << "char c = " << c << endl;

> The output is
>
> uint16_t i16 = 16
> uint8_t i8 =
> char c = C
>
>
> Why is the value for the uint8_t i8 not output? Works fine if I
> change it to a uint16_t.

uint8_t is probably represented by unsigned char, for which IOStreams have
an overload that handles them as characters and not as integers. If you
want them as integers, use a static_cast.

Uli

--
FAQ: http://ma.rtij.nl/acllc-c++.FAQ.html