我有这个代码,想知道是否有可能让 stringstream 将 uint8_t 视为数字而不是字符?
uint8_t s;
std::stringstream sstream( "255" );
sstream >> s;
std::cout << s << " equals 50/'2' not 255 " << std::endl;
s 应该是 255 而不是 50/'2'
最佳答案
如果您使用 std::stringstream 将 uint8_t 转换为字符串,那么您可以使用 std::to_string反而。仅在 c++11 中允许。
C++11 特性
#include <stdint.h>
#include <iostream>
uint8_t value = 7;
std::cout << std::to_string(value) << std::endl;
// Output is "7"
关于stringstream - 如何让 stringstream 将 uint8_t 视为数字而不是字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15047028/