#include<iostream>
#include<string.h>
using namespace std;
int main ()
{
char sentence []= "this is a sentence with 7 tokens";
cout <<"this string to be tokenized is "<<endl<<sentence<<endl;
char *tokenp=strtok(sentence," ");
while (tokenp)
{
cout <<tokenp<<endl;
tokenp=strtok(NULL," ");
//cout <<sentence<<endl;
}
cout <<"after strtok sentence ="<<sentence<<endl;
return 0;
}


本文详细介绍了C++中使用strtok函数进行字符串分词的过程及应用,通过实例展示了如何将连续字符分割成独立的token,对于理解C++字符串处理具有重要意义。
477





