it's already been said but use stringstreams:
Code:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string Token, ToParse("one two three four five");
istringstream StrStream(ToParse);
while (StrStream)
{
getline(StrStream, Token, ' ');
cout << Token << endl;
}
/*
//Alternatively:
while (StrStream >> Token)
{
cout << Token << endl;
}
*/
return 0;
}
Outputs:
one
two
three
four
five
Or you really could just do something like this:
Code:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string FullName("John Smith");
string FirstName, LastName;
istringstream StrStream(FullName);
StrStream >> FirstName;
StrStream >> LastName;
cout << FirstName << endl;
cout << LastName << endl;
return 0;
}
FirstName and LastName will always be valid strings regardless of what FullName is