C ++ structure data element

I work in C ++, Linux and run into a problem like this:

struct testing{
uint8_t a;
uint16_t b;
char c;
int8_t d;

};

testing t;

t.a = 1;
t.b = 6;
t.c = 'c';
t.d = 4;
cout << "Value of t.a >>" << t.a << endl;
cout << "Value of t.b >>" << t.b << endl;
cout << "Value of t.c >>" << t.c << endl;
cout << "Value of t.d >>" << t.d << endl;

The output on my console is:

Value of t.a >>
Value of t.b >>6
Value of t.c >>c
Value of t.d >>

It seems that ta and td are missing for types int8_t and uint8_t. Why is this so?

Thank.

+5
source share
3 answers

The types int8_t and uint8_t are probably defined as char and unsigned char. The stream <operator prints them as characters. Since they are set to 1 and 4, respectively, which are control characters and not printed characters, nothing will be visible on the console. Try setting them to 65 and 66 (“A” and “B”) and see what happens.

:, , :

cout << static_cast<unsigned int>(t.a) << endl;
+10

, operator<< "char".

Try:

cout << "Value of t.a >>" << static_cast<int>(t.a) << endl;
+3

In this page, linux man, int8_t and uint8_t are actually typed as char:

typedef signed char int8_t
typedef unsigned char uint8_t

And the values ​​1 and 4 of char are control characters, as you can find here .

That is why you are not printing anything.

+2
source

All Articles