为什么字符串流只读取整数中的第一个数字?如何使它只在空白处移动?

Why is stringstream only reading the first digit in my integer? How do I make it so it only moves on at a blank space?

本文关键字:移动 何使它 数字 空白处 字符串 读取 整数 为什么 第一个      更新时间:2023-10-16

相关代码如下:

string output;
char letter, number, symbol;
cout << "Input a letter, number, and a symbol separated by a space: ";
getline(cin, output);
istringstream(output) >> letter >> number >> symbol;

但是,如果我输入一个多位数字,它只保存第一个,然后分配给符号的任何内容都是不正确的。

我做错了什么?我怎样才能让它只在遇到空白时停止阅读?

letternumbersymbol都被定义为char类型,因此您只会在每个变量中获取一个字符。尝试将number设为int