πŸ’» Dev & CSC++ Programming

C++ Programming Ch.11 Exercise 5 Solution

Problem: λ‹€μŒ ν”„λ‘œκ·Έλž¨μ€ 예제 11-3의 μ½”λ“œμ΄λ‹€. μ•„λž˜ μ½”λ“œμ—μ„œ char [] λŒ€μ‹  string을 μ΄μš©ν•˜μ—¬ λ¬Έμžμ—΄μ„ 닀루도둝 ν”„λ‘œκ·Έλž¨μ„ μž¬μž‘μ„±ν•˜λΌ. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include #include using namespace std; int main() { char cmd[80]; cout << "cin.get(char*, int)둜 λ¬Έμžμ—΄μ„ μ½μŠ΅λ‹ˆλ‹€." << endl; while(true) { cout << "μ’…λ£Œν•˜λ €λ©΄ exitλ₯Ό μž…λ ₯ν•˜μ„Έμš” >> "; cin.get(cmd, 80); // 79κ°œκΉŒμ§€μ˜ 문자 읽음 if(strcmp(cmd, "exit") == 0 ) { cout << "ν”„λ‘œκ·Έλž¨μ„ μ’…λ£Œν•©λ‹ˆλ‹€...."; return 0; } else cin.ignore(1); // 버퍼에 남아 μžˆλŠ” ν‚€ ('\n') 제거 } } Execution Result: ...

March 27, 2020 Β· 1 min Β· Sobamemil
πŸ’» Dev & CSC++ Programming

C++ Programming Ch.11 Exercise 1 Solution

Problem: int cin.get() ν•¨μˆ˜λ₯Ό μ΄μš©ν•˜μ—¬ ν‚€λ³΄λ“œλ‘œλΆ€ν„° ν•œ 라인을 읽고 'a'κ°€ λͺ‡ κ°œμΈμ§€ 좜λ ₯ν•˜λŠ” ν”„λ‘œκ·Έλž¨μ„ μž‘μ„±ν•˜λΌ. Execution Result: Objective & Hints: cin으둜 ν‚€ μž…λ ₯ μ—°μŠ΅ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include using namespace std; int main() { int a; int cnt=0; while( (a = cin.get() ) != EOF ){ if(a == 'a') cnt++; else if(a == '\n') break; } cout << cnt; } Explanation: ...

March 27, 2020 Β· 1 min Β· Sobamemil