C++中实现字符串函数split
2016-03-22 21:04
351 查看
vector<string> split(string str) { string str; getline(cin,str); vector<string> vec; while(1) { int pos=str.find(' '); if(pos==0) { str=str.substr(1); continue; } if(pos<0) { vec.push_back(str); break; } string tmp = str.substr(0,pos); str=str.substr(pos+1); vec.push_back(tmp); } vector<string>::iterator iter = vec.begin(); for(;iter != vec.end();++iter) cout<<*iter<<" "; return vec; }
相关文章推荐