这个:
#include <iostream>
#include <sstream>
#include <inttypes.h>
using namespace std;
int main (void) {
istringstream iss("123 42");
int8_t x;
while (iss >> x) {
cout << x << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
产生:
1
2
3
4
2
Run Code Online (Sandbox Code Playgroud)
但我想要:
123
42
Run Code Online (Sandbox Code Playgroud)
转换iss >> (int)x(我最初用 a 尝试过char)给了我“错误:二进制表达式的无效操作数('istringstream'(又名'basic_istringstream')和'int')”(clang)或“错误:'operator>>'的模糊重载" (g++)。
有没有办法将值作为数字直接读入8 位类型,还是必须使用中间存储?