The Boost tokenizer class can make this sort of thing quite simple:
***
#include
#include
#include
#include
using namespace std;
using namespace boost;
int main(int, char**)
{
string text = "token, test string";
char_separator sep(", ");
tokenizer< char_separator > tokens(text, sep);
BOOST_FOREACH (const string& t, tokens) {
cout << t << "." << endl;
}
}
***
Updated for C++11:
***
#include
#include
#include
using namespace std;
using namespace boost;
int main(int, char**)
{
string text = "token, test string";
char_separator sep(", ");
tokenizer> tokens(text, sep);
for (const auto& t : tokens) {
cout << t << "." << endl;
}
}
***