I want to write a program that a part of it is that input some numbers that there is some spaces between them for example :1 2 3 and with a while loop i input them i want to have pressing enter key as condition of my while loop but how?
Asked
Active
Viewed 159 times
-1
-
2What language are you using? – Codor Feb 26 '15 at 15:59
-
i m using c++ language – behnam Feb 26 '15 at 16:05
1 Answers
2
stringstream would be useful here.
#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
}
}

Anmol Singh Jaggi
- 8,376
- 4
- 36
- 77