C++一种通过getline()和stringstream类实现split()函数的方法
leetcode 468. 验证IP地址
/*
s = "172.16.254.1";
ip = {};
c = '.'; //getline()的分隔符
*/
void split(const string& s,vector<string>& ip,char c){
stringstream ss(s);
string tmp;
while(getline(ss,tmp,c)) ip.push_back(tmp);
if(s.size() > 0 && s.back() == c) ip.push_back({}); //如果s最后的元素为c,则再在ip后面push_back一个空字符串
}
/*
s = "172.16.254.1";
ip = {"172","16","254","1"};
c = '.';
*/