//str为需要截断的string,pattern为分隔符
std::vector<std::string> split(std::string str,std::string pattern) 
{  
	std::string::size_type pos;   
	std::vector<std::string> result;  
	str+=pattern;//扩展字符串以方便操作   
	int size=str.size();     
	for(int i=0; i<size; i++)   
	{     
		pos=str.find(pattern,i);     
		if(pos<size)     
		{      
			std::string s=str.substr(i,pos-i);       
			result.push_back(s);      
			i=pos+pattern.size()-1;     
		}   
	}   
	return result; 
}

  

版权声明:本文为striver-zhu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/striver-zhu/archive/2004/01/13/4653675.html