sstream을 사용하여 문자열 split 하기 (C++)

sstream을 사용하여 문자열 split 하기 (C++)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

#include < iostream > #include < string > #include < vector > #include < sstream > using namespace std ; int main() { string str = "" ; istringstream ss(str); string stringBuffer; vector < string > v; v.clear(); //구분자가 , 이라면 getline(ss, stringBuffer, ',')쓰면됨 while (getline(ss, stringBuffer, ' ' )) { v. push_back (stringBuffer); } for ( int i = 0 ; i < v. size (); i + + ){ cout < < v[i] < < endl ; } return 0 ; } Colored by Color Scripter

from http://gamedoridori.tistory.com/89 by ccl(A) rewrite - 2021-11-21 04:28:25