I rather like this example from the FAQ
Code:
#include <string>
#include <iostream>
#include <vector>
int main(void)
{
std::string numbers_str = "zero,one,two,three,four,five,six,seven,eight,nine,ten";
std::vector < std::string > numbers; //we'll put all of the tokens in here
std::string temp;
while (numbers_str.find(",", 0) != std::string::npos)
{ //does the string a comma in it?
size_t pos = numbers_str.find(",", 0); //store the position of the delimiter
temp = numbers_str.substr(0, pos); //get the token
numbers_str.erase(0, pos + 1); //erase it from the source
numbers.push_back(temp); //and put it into the array
}
numbers.push_back(numbers_str); //the last token is all alone
std::cout << "Number " << 3 << " is " << numbers[3] << std::endl;
return(0);
}
http://faq.cprogramming.com/cgi-bin/...&id=1044780608
There's also an example for doing something similar in C.