jeudi 23 juillet 2020

Read comma separated integers from getline()

How can I read separate integers from the code below?

while (getline(cin, line)) {
    // for each integer in line do something.....
    // myVector.push_back(each integer)
}

The input is like this: 1, 2, 3, 5 (separated by comma except the last integer).

Sample Input (ignore the line # part):

 line1: 1, 2, 3, 4, 5
 line2: 6, 7, 8, 9, 10
 line3: 3, 3, 3, 3, 3
 /// and so on...

I need to read the integers one by one, and let's say increment and print them.

Aucun commentaire:

Enregistrer un commentaire