-1

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?

Codor
  • 17,447
  • 9
  • 29
  • 56
behnam
  • 100
  • 1
  • 8

1 Answers1

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