#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <chrono>
using namespace std;
void Myprint(string s)
{
cout<<s<<endl;
}
vector<string> Split(string s,string c)
{
vector<string> arr;
string str_t;
int num=0;
do
{
num = s.find(c);
if(num==-1)
{
break;
}
str_t=s.substr(0,num);
arr.push_back(str_t);
s.erase(0,num+1);
} while (true);
arr.push_back(s);
return arr;
}
int main()
{
string str = "abc 123 def";
auto beforetime = chrono::steady_clock::now();
vector<string> arr = Split(str," ");
auto aftertime = chrono::steady_clock::now();
for_each(arr.begin(),arr.end(),Myprint);
double ms = chrono::duration<double,milli>(aftertime-beforetime).count();
cout<<"运行时间"<<ms<<endl;
system("pause");
}
abc
123
def
运行时间0.0235
请按任意键继续. . .