don't cast away const, particularly a const you did not write yourself. Your tokenizer can break in a very subtle manner as str1's destructor is called while strtok's static char* still points to it's buffer. If I may suggest.
Code:
std::string extract_token(std::string &str, const std::string &sep=" \t") {
typedef std::string::size_type pos_t;
pos_t start = str.find_first_not_of(sep);
if(start == std::string::npos) {
str.clear();
return "";
}
pos_t end = str.find_first_of(sep,start); // returns npos on failure
std::string token = str.substr(start,end-start); // if end==npos end-start is huge
str.erase(0,end);
return token;
}
this takes a string and a string of seperator characters and returns the first token and strips the first token off the string you passed it. This is a lot more usefull than strtok() as you can mix extract_token() calls to different strings independantly, rather than being sure you have called strtok(NULL) as often as you are ever going to need to.
The other two handy parsing tricks to know about are stringstream, because many tokens are numbers, and the boost
librarys in particular for regex++, though they also have a fancy tokenizer.