I guess I'm still dwelling in pointer-land... oh well. Actually, did C++
come up with a better strtok()?
Nothing built-in. Here's a utility I wrote, it's not equivilent to
strtok() but rather ones like PHP explode():
#include <vector>
#include <string>
// breaks apart a string into substrings separated by a character string
// does not use a strtok() style list of separator characters
// returns a vector of std::strings
std::vector<std::string> Explode (const std::string &inString,
const std::string &separator)
{
std::vector<std::string> returnVector;
std::string::size_type start = 0;
std::string::size_type end = 0;
while ((end=inString.find (separator, start)) != std::string::npos)
{
returnVector.push_back (inString.substr (start, end-start));
start = end+separator.size();
}
returnVector.push_back (inString.substr (start));
return returnVector;
}
Brian Rodenborn