-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_split.cc
More file actions
33 lines (25 loc) · 760 Bytes
/
string_split.cc
File metadata and controls
33 lines (25 loc) · 760 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
#include "/home/icegpu/HK/HKTool.h"
#include <cstddef>
#include <ios>
using namespace std;
vector<string> split(string input, string delimiter){
vector<string> ret;
long long pos = 0;
string token = "";
while( (pos = input.find(delimiter)) != string::npos ){
token = input.substr(0, pos);
ret.push_back(token);
input.erase(0, pos + delimiter.length());
}
ret.push_back(input);
return ret;
}
void string_split(){
string s = "Hello, this is a coding test code for the coding test.";
string type = " ";
cout << " My input string is : " << s << "\n";
cout << " , And Delimieter is : " << type << "\n";
cout << " String split process result are shown below \n";
vector<string> a = split(s,type);
for(string b : a) cout << b << "\n";
}