C++ preg split() 구현

Jmnote (토론 | 기여)님의 2023년 9월 24일 (일) 14:33 판 (→‎개요)

1 개요

C++ 문자열 split() 구현
C++
Copy
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

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

2 같이 보기