[C++] split 字符串 →→→→→进入此内容的聊天室

来自 , 2020-11-22, 写在 C++, 查看 125 次.
URL http://www.code666.cn/view/3683af9d
  1. void split(const string& str, const string& delimiters , vector<string>& tokens)
  2. {
  3.     // Skip delimiters at beginning.
  4.     string::size_type lastPos = str.find_first_not_of(delimiters, 0);
  5.     // Find first "non-delimiter".
  6.     string::size_type pos     = str.find_first_of(delimiters, lastPos);
  7.  
  8.     while (string::npos != pos || string::npos != lastPos)
  9.     {
  10.         // Found a token, add it to the vector.
  11.         tokens.push_back(str.substr(lastPos, pos - lastPos));
  12.         // Skip delimiters.  Note the "not_of"
  13.         lastPos = str.find_first_not_of(delimiters, pos);
  14.         // Find next "non-delimiter"
  15.         pos = str.find_first_of(delimiters, lastPos);
  16.     }
  17. }

回复 "split 字符串"

这儿你可以回复上面这条便签

captcha