描述
代码里用到一个uint8的枚举量,无法通过log打印观测
即使用static_cast<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