In this HackerRank StringStream problem in c++, we have given a string of comma-delimited integers, return a vector of integers.

HackerRank StringStream in C++ problem solution

HackerRank StringStream in C++ problem solution

#include <sstream>
#include <vector>
#include <iostream>
using namespace std;

vector<int> parseInts(string str) {
   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;
}