string split

 根据空格split
string str = "abc def,ghi";
stringstream ss(str);

string token;

while (ss >> token)
    cout<<token<<endl; 

output:
abc
def,ghi



根据指定字符split
vector<string> result;
string tmp;
string toBeSplited;
stringstream ss(toBeSplited);
while(getline(ss, tmp, '/')) {
  result.push_back(tmp);  
}

 

 
 
posted @ 2016-01-10 01:32  飞飞喵  阅读(133)  评论(0)    收藏  举报