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