分类: 技术杂文

c++ explode()

用惯了php里的explode函数,迁移到c++觉得无所适从

网上找了这个方法,经过验证可以使用,中文也行

/*
 * C++ Explode Function
 * Written by Alec Hussey
 * License: Public Domain
 */

#include 
#include 
#include 
#include 

std::vector explode(char *sep, std::string src)
{
	std::vector output;
	boost::char_separator separator(sep);
	boost::tokenizer > tokens(src, separator);
	boost::tokenizer >::iterator token_iter;

	for (token_iter = tokens.begin(); token_iter != tokens.end(); token_iter++)
		output.push_back(*token_iter);

	return output;
}
Share