加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

C struct数据成员

发布时间:2020-12-13 19:09:46 所属栏目:Linux 来源:网络整理
导读:我在C,Linux工作,遇到以下问题: 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 Value of t.b 6Value of t.c cValue of t.d 对于int8_t和uint8_t类型,似乎

我在C,Linux工作,遇到以下问题:

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;

我的控制台上的输出是:

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

对于int8_t和uint8_t类型,似乎缺少t.a和t.d.为什么会这样?

谢谢.

最佳答案
int8_t和uint8_t类型可能被定义为char和unsigned char.流<<运算符将输出为字符.由于它们分别设置为1和4,它们是控制字符而不是打印字符,因此控制台上不会显示任何内容.尝试将它们设置为65和66('A'和'B'),看看会发生什么. 编辑:要打印出数字而不是字符,您需要将它们转换为适当的类型:

cout << static_cast

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读