描述

代码里用到一个uint8的枚举量,无法通过log打印观测
即使用static_cast<uint8_t>转换依然无法正常输出
c++有关uint8_t打印异常那些事

原因

看到图片第一反应是ASCII码问题,查询资料进一步印证猜想

uint8_t is an alias for unsigned char, and the iostreams have special overloads for chars that print out the characters rather than formatting numbers.

枚举量范围0-3,而小于32的char对应ASCII不可见符号

解决

原因明确,只要将uint8_t的值还原成对应字符即可正常打印,参考so添加unsigned()解决

uint8_t aa=5;

cout << "value is " << unsigned(aa) << endl;

对于枚举量+aa并不能解决问题

参考

c++ - uint8_t iostream behavior - Stack Overflow
c++ - uint8_t can't be printed with cout - Stack Overflow

相关文章:

  • 2021-12-25
  • 2021-11-20
  • 2021-11-20
  • 2021-08-22
  • 2021-08-25
  • 2022-12-23
  • 2022-03-04
猜你喜欢
  • 2021-11-20
  • 2022-12-23
  • 2021-03-28
  • 2022-01-19
  • 2021-04-10
  • 2022-12-23
  • 2022-01-09
相关资源
相似解决方案