Convert non zero ended string to int

Hi guys.

I need to parse such string to list (or array) of ints:
"10; 20; 345; 45"
I though to do this so:

1
2
3
4
5
6
7
8
9
10
11
12
13
std::list<int> lst;
const char *cur = str;
while (*cur) {
   cur = skip_whitespaces(cur);       // pointer to non whitespace char or '\0'
   if (*cur == '\0')
       break;
   const char *end = find_delim(cur + 1); // pointer to delimiter char or '\0'
   int error;
   int value = strtoint(cur, end, &error);
   if (!error)
       lst.push_back(value);
   cur = end;
}


i've thought of using strstream or atoi (strtol), but this seems better.

So i there any function like strtoint?.

Thanks.
Last edited on
Last edited on
Thanks.
It seems that it's really easy to use streams.
Topic archived. No new replies allowed.