i want read first line of standard input, , place the values vector (unknown number of entries). each vector element holding value (i.e. vector[1]=1
, vector[2]=-30
...)
e.g.
1 -30 10 300
i've tried using while loop , cin
, can't seem make stop @ terminating character /n
. , i've been trying implement getline
, i'm having no luck. there method store integers standard input, vector?
any appreciated, thank in advance. :)
the below code works fine problem. answer mohit should use getline not readline
vector <int> vec; string input; getline(cin,input); istringstream ss(input); int num; while (ss >> num) { vec.push_back(num); } vector<int>::iterator itr = vec.begin(); while (itr != vec.end()) { cout << *itr << endl; itr++; }
the snippet prints standard output.
Comments
Post a Comment