C++/c++
#include <conio.h> _getch() ์ค๋ช ๊ณผ ์ฝ๋ ์์
Rainbow๐Coder
2021. 5. 25. 16:13
728x90
#include <conio.h>
์ฝ์ input output ํค๋ํ์ผ์ด๋ค.
์ฝ์์ฐฝ์์ ์ ์ถ๋ ฅํ๋ ๊ธฐ๋ฅ๋ค์ ์ ๊ณตํด์ฃผ๋ ํค๋ํ์ผ์ด๋ค.
_getch()
_getch() ํจ์๋ ๋ฌธ์ 1๊ฐ๋ฅผ ์ ๋ ฅ๋ฐ๋ ํจ์์ด๋ค.
Enter๋ฅผ ์น์ง ์๋๋ผ๋ ๋ฌธ์๋ฅผ ๋๋ฅด๋ ์๊ฐ ๋ฐ๋ก ๊ทธ ๋ฌธ์๋ฅผ ๋ฐํํ๊ณ ์ข ๋ฃ๋๋ค.
๋ค์ ๋งํด, cin ์ฒ๋ผ ์ ๋ ฅํ ๋ค์ ๊ตณ์ด ์ํฐ๋ฅผ ์ถ๊ฐํ ํ์์์ด
์ ๋ ฅ ํ์ธํด์ค๋ค.
<์ฝ๋ ์์>
ํค๋ณด๋์์ q๋ฅผ ๋๋ ์ ๋ ๊ฒ์ ์ข ๋ฃํ๊ณ ์ถ์ ๋ ์์ฑํ๋ ์ฝ๋
#include <iostream>
#include <time.h>
#include <conio.h>
using namespace std;
int main(){
while(true){
char key = _getch();
if(key=='q'|| key=='Q')
break;
}
cout<<"๊ฒ์์ ์ข ๋ฃํฉ๋๋ค."<<endl;
return 0;
}
728x90