-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (35 loc) · 838 Bytes
/
main.cpp
File metadata and controls
41 lines (35 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<string> split(string s, string d){
int x=s.find(d);
vector <string> g;
while (x!=string::npos){ //if x has no value stop
if (x==0){
s=s.substr(x+1);
x=s.find(d);
continue;
}
g.push_back(s.substr(0,x));
s = s.substr(x+1);
x = s.find(d);
if (x==string::npos){
g.push_back(s);
}
}
return g;
};
int main()
{
vector<string> v;
string st;
string de;
cout << "Enter string: "<< endl;
getline(cin, st);
cout << "Enter delimiter:" << endl;
getline(cin, de);
v = split(st, de);
for (int i = 0; i < v.size(); i++)
cout << "'"<<v[i] << "'";
}