#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char sentence[] = "This is a sentence with 7 tokens";
cout << "The string to be tokenized is:\n" << sentence << "\n\nThe tokens are:\n\n";
char *tokenPtr = strtok(sentence," ");
while(tokenPtr != NULL)
{
cout <<tokenPtr << '\n';
tokenPtr = strtok(NULL, " ");
}
cout << "After strtok, sentence = " << sentence <<endl ;
return 0;
}
分割字符串
最新推荐文章于 2021-03-24 11:26:36 发布