Created
July 16, 2019 19:12
-
-
Save ivary43/4769d7281b2b8f6717ae932dd8f94b25 to your computer and use it in GitHub Desktop.
A wrapper/alternative of strtok() c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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