为什么字符串流只读取整数中的第一个数字?如何使它只在空白处移动?
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?
相关代码如下:
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;
但是,如果我输入一个多位数字,它只保存第一个,然后分配给符号的任何内容都是不正确的。
我做错了什么?我怎样才能让它只在遇到空白时停止阅读?
letter
、number
和symbol
都被定义为char
类型,因此您只会在每个变量中获取一个字符。尝试将number
设为int
。
相关文章:
- 我如何使它,无论用户用空白字符串按 Enter 多少次,它总是打印"开始"字符串?
- 如何使它看起来像正在下的雪
- 为什么字符串流只读取整数中的第一个数字?如何使它只在空白处移动?
- 将 std::atomic_flag 包裹在吸气剂/二传手中会使它的"atomicity"无效吗?
- 该代码不会在其中显示任何数字输入.如何使它显示任何输入
- 为什么输出是 2 而不是 7 ?+ 号如何使它与众不同
- 无论如何,是否可以使用setCursorPos(int,int)函数,但没有采用两个int使它需要速度较慢的两倍
- 是否允许复制/移动省略使使用已删除函数的程序格式正确?
- 绘制移动图标,它一直是最顶端的鼠标光标和工作的全屏应用程序
- POD 类中的嵌套枚举是否使它不是 POD
- 使用 CSplitterWindowImpl 处理移动并使子窗格无效
- 多个线程同时在unordered_map中添加值会使它崩溃
- C++MessageBox(Windows.h)-它做什么以及如何使它不可见(或等效)
- 如何在c++ dll中实例化一个类,使它在函数调用之间保持内存
- 在QTableWidget中添加一个QPushButton到qtablewidgetiitem,如何使它Qt::Alig
- 延迟初始化缓存..我如何使它线程安全
- 移动是否使对象处于可用状态
- 如何修改一个类,使它只有一个成员函数,所有参数默认
- ' std::sort '在内部使用了什么魔法使它更快?
- 比较两个向量,使它更有效