c++ split实现

之前看的谁出的面试题来着。不太记得了。

不过今天水微软的编程之美第一题的时候我用了split,所以就实现了一个。

当然可能还不满足那个面试题的要求,因为我只是用了istringstream而已。

先写在这儿吧,过两天再来做那个面试题。

 

std::vector<std::string>& split(const std::string& ori , char ch , std::vector<std::string>& ans)
{
	std::istringstream iss(ori);
	std::string item;
	while(std::getline(iss , item , ch)) ans.push_back(item);
	return ans;
}
std::vector<std::string> split(const std::string& ori , char ch)
{
	std::vector<std::string> ans;
	split(ori , ch , ans);
	return ans;
}

 

原文链接: https://www.cnblogs.com/x1957/archive/2013/04/06/3002558.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    c++ split实现

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/83447

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午9:05
下一篇 2023年2月9日 下午9:05

相关推荐