#include <bits/stdc++.h>
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;
}
예시
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;
}
int main(void) {
vector<string> tmp = split("Hello World! Bye World!", " ");
for (auto token : tmp)
cout << "token = " << token << "\n";
return 0;
}

'개발 > Tip' 카테고리의 다른 글
재귀함수 사용 시 코드 실행시간을 단축하는 방법 (C++) (0) | 2023.07.14 |
---|---|
백준 + 프로그래머스 + SWEA 자동 커밋 익스텐션 (0) | 2023.07.06 |
vscode - code snippet 사용법 (C++) (0) | 2023.03.24 |
(mac) VScode - Code Runner 사용해서 .cpp 코드 실행하기 (0) | 2023.03.16 |