* Computer Science/C++

c++로 스플릿하기

soicem 2018. 9. 27. 20:26

 c++로 스플릿을 하려면 boost나 istringstream을 써야하는듯 하다.  istringstream을 사용해서 split하는 방법을 기록해둔다.


1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <sstream>
 
using namespace std;
 
int main(){
    int num;
    // string split in cpp
    istringstream iss("10 20 30 40");
    while (iss >> num) cout << num << " ";
    return 0;
}
 
cs