I want to read integers from STDIN, 1,2,3,4
vector<int> r;
cin >> is;
stringstream iss(is);
int n;
while(iss >> n)
{
r.push_back(n);
}
but stops reading after "," is there a way other than splitting and directly read Integers only.
I want to read integers from STDIN, 1,2,3,4
vector<int> r;
cin >> is;
stringstream iss(is);
int n;
while(iss >> n)
{
r.push_back(n);
}
but stops reading after "," is there a way other than splitting and directly read Integers only.
Here you have to consume and skip the ,
after every digit as shown here:
vector<int> r;
cin >> is;
stringstream iss(is);
int n;
while(iss >> n)
{
r.push_back(n);
char c;
iss >> c;
}
See running example here.