编辑代码

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

void split(string &s,vector<string> &v,string split_char)
{
    int pos=0;
  
    auto tmp=s.find_first_of(split_char,pos) ;
    while(tmp!=string::npos)
    {
        v.push_back(   s.substr(pos,tmp-pos)  );
        // cout<<s.find_first_of(split_char,pos)  ;
        pos=tmp+1;
        tmp = s.find_first_of(split_char,pos);
    }
    if (pos<s.size()-1)
        v.push_back(   s.substr(pos,s.size()-pos)  );
}

int main() {
    string s="abc df ghi jkllll 1 123 ";
    string split_char=" ";
    vector<string> v;
    
    split(s,v,split_char);
    for(auto i:v)
    cout<<i<<' ';
}