描述

代码里用到一个uint8的枚举量,无法通过log打印观测

即使用static_cast<uint8_t>转换依然无法正常输出

c++有关uint8_t打印异常那些事_c++

原因

看到图片第一反应是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​


Scan error on column index 1, name “created_at“: unsupported Scan, storing driver.Value type []uint8

使用gorm,出现以下报错 在连接数据库时加上: parseTime=True db, err = gorm.Open(utils....