[C++] ๋ฌธ์์ด(string)์ ํน์ ๋ฌธ์๋ก ์๋ฅด๊ธฐ
2021. 4. 24. 03:31
๋ฌธ์์ด์ sstream์ ์ฌ์ฉํ์ฌ ํน์ ๋ฌธ์์ด๋ก ๊ตฌ๋ถํ์ฌ ์๋ฅด๊ธฐ ์๋ ์ฝ๋๋ ๊ณต๋ฐฑ ๋ฌธ์๋ฅผ ๊ธฐ์ค์ผ๋ก ์๋ฅด๋ ๋ฐฉ๋ฒ #include #include #include using namespace std; int main() { string fruit = "apple lemon grape melon"; istringstream ss(fruit); vector words; string word; while (getline(ss, word, ' ')) //๊ณต๋ฐฑ ๋จ์๋ก ๊ตฌ๋ถ words.push_back(word); //words์๋ apple, lemon, grape, melon์ด ์ ์ฅ๋จ }