+ 1

Please explain me this code with example mainly the while loop !!!!

#include <sstream> #include <vector> #include <iostream> using namespace std; vector<int> parseInts(string str) { // Complete this function vector<int> ret; int a; char ch; stringstream s; s.str(str); while(!s.eof()) { s >> a; ret.push_back(a); s >> ch; } return ret; } int main() { string str; cin >> str; vector<int> integers = parseInts(str); for(int i = 0; i < integers.size(); i++) { cout << integers[i] << "\n"; } return 0; }

25th Feb 2022, 11:14 AM
Sabnis Ashutosh
Sabnis Ashutosh - avatar
1 Odpowiedź
0
eof = end of file, iterate while no more element in the file, or iterate while the current element is a tag which is the end of file tag
25th Feb 2022, 1:15 PM
Domonkos Gyömörey
Domonkos Gyömörey - avatar