Parsing a string

I have to parse a string of numbers, separated by commas(i.e. 1,2,3,45,677,89,234,...etc.). I can get almost all of it, but I am having trouble getting the last number to work (when I output the broken up string, it skips the last number).
I am able to get the final number output, but only if I put the cout statement outside of my 'for' loop. However, in my program I need to USE the numbers, rather than just output them.

My current code only uses substr starting at position 0, and ending at string.find(','), but I cannot find a way to include my final number, since the final number has no comma at the end.

Here is my code so far:

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main()
string number, items;
int pos=0;
while (cin>>items)
for (unsigned int i=0;i<=items.length();i++)
if (pos!=string::npos)

cout << item << endl;
return 0;
Topic archived. No new replies allowed.