#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string> split(const string& str, const string& pattern)
{
vector<string> res;
if ("" == str)
return res;
string strs = str + pattern;
size_t pos = strs.find(pattern);
size_t size = strs.size();
while (pos != string::npos)
{
string x = strs.substr(0, pos);
res.push_back(x);
strs = strs.substr(pos + 1, size);
pos = strs.find(pattern);
}
return res;
}
int main()
{
string str = "abc/def/ghi";
vector<string> res = split(str, "/");
for (auto r : res)
{
cout << r << endl;
}
return 0;
}
/*输出结果:
abc
def
ghi
*/