直接模拟
vector方法二get(string str){ vector res; string word; for (auto c: str){ if (c == ' '){ res.push_back(word); word = ""; } else word += c; } res.push_back(word); return res; }
利用substr进行字符串截取
vectorget(string str) { vector res; string word; for(int i = 0, j = 0; i <= str.size(); ++i) { if(i == str.size() || str[i] == ' ') { word = str.substr(j, i-j); j = i+1; res.push_back(word); } } return res; }
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈



