码迷,mamicode.com
首页 > 编程语言 > 详细

c++字符串分割方法

时间:2015-01-26 19:25:25      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

平常做项目都是用java语言,搞毕业论文的时候,需要用到opengl,而opengl和c++的关系很密切并且参考资料也比较丰富,在程序开发的过程用中到了字符串分割,查api竟然没有找到自带的split函数,在这里记录一下c++字符串分割方法。
static void split(const string& src, const string& separator, vector<string>& dest)
{
	string str = src;
	string substring;
	string::size_type start = 0, index;
	do
	{
		index = str.find_first_of(separator,start);
		if (index != string::npos)
		{    
			substring = str.substr(start,index-start);
			dest.push_back(substring);
			start = str.find_first_not_of(separator,index);
			if (start == string::npos) return;
		}
	}while(index != string::npos);
	//the last token
	substring = str.substr(start);
	dest.push_back(substring);
}


c++字符串分割方法

标签:

原文地址:http://blog.csdn.net/wj512416359/article/details/43154639

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!