【发布时间】:2015-04-29 02:22:08
【问题描述】:
我想编写一个程序,它的一部分是输入一些数字,它们之间有一些空格,例如:1 2 3 并使用 while 循环输入它们 我想按回车键作为我的while循环的条件,但是如何?
【问题讨论】:
-
你使用什么语言?
-
我使用c++语言
标签: c++ while-loop enter
我想编写一个程序,它的一部分是输入一些数字,它们之间有一些空格,例如:1 2 3 并使用 while 循环输入它们 我想按回车键作为我的while循环的条件,但是如何?
【问题讨论】:
标签: c++ while-loop enter
stringstream 在这里很有用。
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int x;
string input;
getline( cin, input );
stringstream ss( input );
while ( ss >> x )
{
// Do something with x
}
}
【讨论】: