[C++] stringstream

์œค๊ฒฝยท2021๋…„ 9์›” 6์ผ
0

C++

๋ชฉ๋ก ๋ณด๊ธฐ
18/20
post-custom-banner

stringstream

: ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์—์„œ (๊ณต๋ฐฑ, '\n'์„ ์ œ์™ธํ•˜๊ณ ) ํ•„์š”ํ•œ ์ž๋ฃŒํ˜•์— ๋งž๋Š” ์ •๋ณด๋ฅผ ๊บผ๋‚ผ ๋•Œ ์‚ฌ์šฉ

ํ•„์š” ํ—ค๋”: #include <sstream>

โฌ‡๏ธ ์˜ˆ์ œ ์ฝ”๋“œ

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main() {
    int num;
    string s;
    string str1 = "1122 9 9 987", str2 = "stringstream ์˜ˆ์ œ๋‹ค !!";
    stringstream stream1, stream2(str2);

    stream1.str(str1);
    while(stream1 >> num) {
        cout << num << '\n';
    }

    while(stream2 >> s) {
        cout << s << '\n';
    }

    return 0;
}

โฌ‡๏ธ ์ถœ๋ ฅ ๊ฒฐ๊ณผ

1122
9
9
987
stringstream
์˜ˆ์ œ๋‹ค
!!

stream.str(string str): ํ˜„์žฌ stream ๊ฐ’์„ ๋ฌธ์ž์—ด str๋กœ ๋ฐ”๊ฟˆ
stream.str(""): ์ดˆ๊ธฐํ™”
strean.clear(): (โœ”๏ธ ์ฃผ์˜) ์ €์žฅ๋œ ๋ฌธ์ž์—ด์„ clear ์‹œํ‚ค์ง„ ์•Š์ง€๋งŒ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ›์•˜์„ ๋•Œ ์ฒซ๋ฒˆ์งธ ์œ„์น˜๋ถ€ํ„ฐ ์ถ”์ถœ ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•จ


์ฐธ๊ณ 
์ฐธ๊ณ 

profile
๊ฐœ๋ฐœ ๋ฐ”๋ณด ์ด์‚ฌ ์ค‘
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€