The difference between getch getche and getchar in c

  • 2020-04-02 01:36:51
  • OfStack

getchar Stdio.h is a library function that reads a character from a stdin stream, meaning that if stdin has data, it can be read without input. Getch () and getche() are library functions in conio.h that receive characters from the keyboard.

Getch () Is actually an input command, receive a character from the keyboard, and it's not the display characters, that is to say, it's not after you press a key on the screen you press what, and continue to run the back of the code, so we can use it in the c + + to achieve the effect of the "press any key to continue", namely the program encountered in getch (); This line, it will pause the program, wait for you to press any key, it received the character key and then continue to execute the following code.

You might ask why we didn't add getch() to the end of the program in C++. The explanation is that the software is always updated, and the bad things must be corrected. With this in mind, C++ automatically stops the screen and says "press any key... Asking you to press any key to exit is like C++ running the program in its environment, automatically adding a line of getch() to the end of the program; Statement, and a line of output statement cout is added before the line < < "Press any key..." ; To tell you that the program is over, press any key to continue.

Getche () Much like getch(), it also needs to introduce the header file conio.h, so what's the difference between them? The difference is that getch() returns no display and getche() does.


Related articles: