来自《C++ 程序员教程》
#include<iostream>
using std::cout;
using std::endl;
#include<cstring>
using std::strtok;
int main()
{
char sentence[]="This is my love";
char* tokenPtr;
cout<<"The string to be tokenized is:\n"<<sentence
<<"\n\nThe tokens are:\n\n";
tokenPtr=strtok(sentence," ");
while(tokenPtr!=NULL)
{
cout<<tokenPtr<<'\n';
tokenPtr=strtok(NULL," ");//get next token
}
cout<<"\nAfter strtok,sentence="<<sentence<<endl;
return 0;
}