본문 바로가기

C++

C++ String 띄어쓰기 단위로 자르기

1
2
3
4
5
6
7
8
9
10
11
12
#include <string>
#include<sstream>
 
int main(){
    string myString='12 34 56';
    string a, b, c;
    stringstream s(binomial);
    s >>>> b >> c;
 
    //while은 다음과 같이 사용하자
    while (s1 >> a)
}
cs

1. #include을 추가한다

2. stringstream s(binomial); 추가하여 String 변수를 단어 분리한다

3. 저장한다 while로 설정하여 각각 저장도 가능하다.