C++ Programming Ch.11 Exercise 2 Solution
Problem: istream& get(char& ch) ํจ์๋ฅผ ์ด์ฉํ์ฌ ํ ๋ผ์ธ์ ์ฝ๊ณ ๋น์นธ(' ')์ด ๋ช ๊ฐ์ธ์ง ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ผ. Execution Result: Objective & Hints: cin์ผ๋ก ํค ์ ๋ ฅ ์ฐ์ต Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include using namespace std; int main() { char ch; int cnt; while(true){ cin.get(ch); // ํค๋ฅผ ch์ ์ฝ์ด์ด if(cin.eof()) // EOF ๋ฌธ์ ์ฆ ctrl-z ํค๊ฐ ์ ๋ ฅ๋ ๊ฒฝ์ฐ, ์ฝ๊ธฐ ์ข ๋ฃ break; if(ch == '\n') // ํค๊ฐ ์ ๋ ฅ๋ ๊ฒฝ์ฐ ์ฝ๊ธฐ ์ค๋จ break; else if(ch == ' ') cnt++; } cout << cnt; }