I am working in C++, Linux and I encounter the problem as following:
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 like the t.a and t.d is missing for the int8_t and uint8_t type. Why is it so?
Thanks.
The int8_t and uint8_t types are probably defined as char and unsigned char. The stream << operator is going to output them as characters. Since they're set to 1 and 4 respectively, which are control characters and not printing characters, nothing will be visible on the console. Try setting them to 65 and 66 ('A' and 'B') and see what happens.
EDIT: to print out a numeric value instead of a character, you will need to cast them to an appropriate type:
cout << static_cast<unsigned int>(t.a) << endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With