Skip to content

Instantly share code, notes, and snippets.

@ivary43
Created July 16, 2019 19:12
Show Gist options
  • Save ivary43/4769d7281b2b8f6717ae932dd8f94b25 to your computer and use it in GitHub Desktop.
Save ivary43/4769d7281b2b8f6717ae932dd8f94b25 to your computer and use it in GitHub Desktop.
A wrapper/alternative of strtok() c
#include<bits/stdc++.h>
vector<string> stringSpilt(string str, string delimeter) {
vector<string> res ;
int n = (int)str.length();
char ch_arr[n+1];
strcpy(ch_arr, str.c_str());
const char* temp_delimeter = delimeter.c_str();
char* token = strtok(ch_arr, temp_delimeter);
while (token != NULL)
{
string temp(token);
res.push_back(temp);
token = strtok(NULL, "-");
}
return res ;
}
int main() {
string s, delimeter ;
cin>>s ;
cin>>delimeter;
vector<string> tok = stringSpilt(s, delimeter);
vector<string>:: iterator it ;
for(it=tok.begin(); it!=tok.end();++it){
cout<<*it<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment