본문 바로가기
[C++]

stringstream 실험

by Hevton 2023. 8. 7.
반응형

아래 출력은 어떻게 될까?

#include <iostream>
#include <sstream>

using namespace std;

int main() {
    
    string str1 = "13 123 13fDfcC 32";
    stringstream ss1(str1);
    int num1;

    while (ss1 >> num1) cout << num1 << endl;

}

 

13

123

13

 

이 끝이다.

 

다음 DfcC를 문자열로 받기 전까지 32를 받을 순 없다.

그래서 while문도 탈출된다.

 

반응형