C++中string沒有自帶的split()函數,需要自己實現
void split(const string& s, vector<int>& sv, const char flag = ' ') { sv.clear(); istringstream iss(s); string temp; while (getline(iss, temp, flag)) { sv.push_back(stoi(temp)); } return; }
使用了stringstream,需要在頭文件包含 #include <sstream>
轉載自其他博客