Reading line of integers into a vector(将整行整数读入向量)
问题描述
请看下面的代码
我在这里尝试做的是这样的
What I am trying to do here is something like this
- 输入数字列表(例如:1 2 3 4 5 6 7 8 9 0 11)
- 将它们全部读入向量
- 打印它们
在这里,当我按回车键时,什么也没有发生!似乎循环没有退出.当我按下回车键时如何打印值?
In here, when I hit enter, nothing is happening! Seems like the loops didn't exit. How to print the values when I hit the enter?
更新
我按照答案中给出的建议编辑了代码.
I edited the code as advises given in answers.
但它现在给出了另一个错误
but it gives another error now
推荐答案
使用 getline
.然后将该字符串放入istringstream
.然后从 istringstream
中读取,而不是你现在使用 cin
的地方.
Read in a line from cin into a string using getline
. Then put that string into an istringstream
. Then read from that istringstream
in place of where you're using cin
now.
这篇关于将整行整数读入向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!