I have a string of different integers separated by a comma. For example "45,67,2,3,8,9,123,5,6,3,9,4,7,2,4,4,5,69,9,99". I want to read this line as a stringstream and put integers to the vector of integers. On the console, it displays "no response on stdout".
The code looks as follows:
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;
vector<int> parseInts(string str) {
stringstream myString;
vector<int> of_integers;
char ch;
int a;
for(int k = 0; k<str.size(); k++)
{
myString >> a >> ch;
of_integers[k] = a;
}
return of_integers;
}
int main() {
string str;
cin >> str;
vector<int> integers = parseInts(str); //function parseInts
for(int i = 0; i < integers.size(); i++) {
cout << integers[i] << "\n";
}
return 0;
}