C++实现类似Java中split()功能
#include <bits/stdc++.h>
using namespace std;
vector<string>split(string str, char c)
{
vector<string>res;
string t;
str += c;
for (int i = 0; i < str.size(); i++)
{
if (str[i] == c)res.push_back(t), t = "";
else t += str[i];
}
return res;
}
int main()
{
char c;
string str;
vector<string>s;
getline(cin, str);
c = ' ';//根据需求更改
s = split(str, c);
for (auto x : s)cout << x;
return 0;
}