C++ string은 따로 Split함수가 없다. 따로 정의를 해야 된다.
delimeter : 구분 시킬 기준값
코드
vector<string> split(string input, string delimeter)
{
vector<string> ret;
long long pos;
string token;
while((pos = input.find(delimeter)) != string::npos)
{
token = input.substr(0, pos);
ret.push_back(token);
input.erase(0, pos + delimeter.length());
}
ret.push_back(input);
return ret;
}
'알고리즘 > 기본 문법' 카테고리의 다른 글
<알고리즘> 모듈러 연산 (0) | 2022.04.21 |
---|---|
<알고리즘> 최대공약수/최소공배수 (0) | 2022.04.21 |
<알고리즘> 조합(Combination) (0) | 2022.04.21 |
<알고리즘> 순열(permutation) (0) | 2022.04.21 |
<알고리즘> 구조체를 이용한 커스텀 정렬 (0) | 2022.04.19 |