-8
#include<striang>
#include<iostream>
#include<sstream>
#include<stdlib.h>
using namespace std;
int main()
{
    string line;
    cin>>line;
    istringstream iss(line);
    int i, count, numbers[100];
    count = 0;
    do
    {
        string sub;
        iss >> sub;

        numbers[count] = atoi(sub.c_str());
        count++;

    } while (iss);

    cout<<"Numbers"<<endl;

    for (i=0; i<count;i++)
      cout<<numbers[i]<<endl;

}

For the input

 1                   2      3  -4   8

I need the output

 1 2 3 -4 8
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190

1 Answers1

0

As mentioned in @Jhonny Mopp's comment the primary problem is, that you don't read a whole line here:

cin>>line;

it just reads up to the next whitespace delimiter.

What you actually want is:

getline(cin, line);

This would read in the whole input until you hit Enter.


Regarding the rest of processing refer to that Q&A I formerly marked as duplicate:

How to test whether stringstream operator>> has parsed a bad type and skip it

Community
  • 1
  • 1
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • @TaGiAsadullazadeh _"great"_ Not really. Take a look at your question score. I've just been answering because this would have been too long and poorly formatted as a comment. Please do a bit better research before asking the next time. There's plenty of [material to be found](http://en.cppreference.com/w/cpp/io/basic_istream/operator_gtgt2), why `cin >> line;` doesn't work like your expect it to do. – πάντα ῥεῖ Jun 01 '16 at 18:56