- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit.cpp
More file actions
Latest commit
29 lines (23 loc) · 686 Bytes
/
Copy pathsplit.cpp
File metadata and controls
29 lines (23 loc) · 686 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
/* split 메소드 구현하는 코드 */
#include<bits/stdc++.h>
usingnamespacestd;
vector<string> split(const string& input, string delimeter) {
vector<string> result;
auto start = 0;
auto end = input.find(delimeter);
while (end != string::npos) {
result.push_back(input.substr(start, end - start));
start = end + delimeter.size();
end = input.find(delimeter, start);
}
result.push_back(input.substr(start));
return result;
}
intmain() {
string str = "apple,banana,orange,grape";
vector<string> fruits = split(str, ",");
for (const string& fruit : fruits) {
cout << fruit << "\n";
}
return0;
}