๐ฝ
main.cpp
๐ฝ
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
string s = "abc def gh ij klm no";
vector<string> v;
string delimiter = " ";
// Starting from the beginning.
// 0U means unsigned 0.
auto start = 0U;
auto end = s.find(delimiter);
string token = "";
while (end != string::npos) {
token = s.substr(start, end-start);
v.push_back(token);
start = end + delimiter.length();
end = s.find(delimiter, start);
}
v.push_back(s.substr(start));
for(const auto &item: v)
cout<<item<<endl;
return 0;
}
๐ฝ
Output
๐ฝ
~/Desktop/Desktop/CS/Practical/Algorithms/Algorithm/Split main ?1 โฏ ./main.out 18:29:01
abc
def
gh
ij
klm
no
delimiter
์ ์ํด ๋ฌธ์์ด์ ๋๋ ์ ๋ฒกํฐ์ ์ ์ฅํ๋๋ฒ.