If you mean with C style strings then you can just use strtok in <cstring>, if you mean with the string class then you can do something like this
Code:
#include <iostream>
#include <string>
string bad_char = " ";
string next_token(string& s, string::size_type& pos)
{
size_t begin = s.find_first_not_of(bad_char, pos);
size_t end = s.find_first_of(bad_char, begin);
pos = end;
if (begin == string::npos)
{
return string();
}
else if (end == string::npos)
{
return s.substr(begin);
}
else
{
return s.substr (begin, end - begin);
}
}
int main()
{
string::size_type pos = 0;
string s = "Breaking up a string";
string t;
while (!(t = next_token(s, pos)).empty())
{
cout<< t <<endl;
}
}