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

不过今天水微软的编程之美第一题的时候我用了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;
}

 

相关文章:

  • 2021-10-30
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-01-14
  • 2022-01-30
猜你喜欢
  • 2022-01-07
  • 2021-11-14
  • 2021-06-21
  • 2022-12-23
  • 2022-02-23
  • 2022-02-17
  • 2022-12-23
相关资源
相似解决方案