you can use strtok() -- warning, that function changes the string, so if you need the original string later in the program you will have to make a copy of it before calling strtok() the first time.
std::string str = "48098, 50933, 3128, 323, 42, 5";
int n;
char* ptr = strtok((char*)str.c_str(),",");
while(ptr != 0)
{
n = atoi(ptr); // you will probably want to put the ints into
// some sort of array or vector
ptr = strtok(0,",");
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
If the current protocol is satisfactory for you, so be it. You might also be able to accomplish essentially the same thing by processing each number as you read it in, rather than read in all the numbers at once and parse the whole file/string. To do that, I'd use getline() with comma as the delimiting character to read a string representing a single number into a buffer and convert the buffer on the fly. This approach might work better if you don't know the number of numbers or the number of digits in the numbers you're going to need to hold the composite string and you aren't hardcoding the string but reading it on the fly.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396