您的位置:首页 > 编程语言 > C语言/C++

重学C++ 用strtok标记字符串

2013-04-23 15:26 176 查看
来自《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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: