C++ preg split() 구현

Jmnote (토론 | 기여)님의 2023년 9월 24일 (일) 14:32 판 (새 문서: ==개요== ;C++ 문자열 split() 구현 <syntaxhighlight lang='cpp' run> #include <iostream> #include <sstream> #include <vector> using namespace std; int main() { string s = "...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

C++ 문자열 split() 구현
C++
CPU
0.4s
MEM
56M
0.5s
Copy
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

int main() {
    string s = "abc,defgh,ijk";
    
    vector<string> strs;
    istringstream iss(s);
    for (string s; getline(iss, s, ','); ) {
        strs.push_back(s);
    }
    for (string str: strs) {
        cout << str << ' '; // abc defgh ijk 
    }
}
abc defgh ijk 

2 같이 보기