The difference of Getch,getche,getchar in C language _c language

Source: Internet
Author: User
Tags stdin

GetChar is a library function in stdio.h that reads a character from the stdin stream, which means that if stdin has data, it can be read directly without input. The Getch () and Getche () are library functions in Conio.h, which is the function of receiving characters from the keyboard.

getch () is actually an input command that receives a character from the keyboard and does not display the character, that is, after you press a key it does not display what you press on the screen and continues to run the following code, so we are in C + + You can use it to achieve the "press any key to continue" effect, that is encountered in the program Getch (), this line of statements, it will suspend the program, and so you press any key, it received the word keys and then continue to execute the following code.

You may ask why we did not add getch () to the end of the program in C + +. Explanation is that the software is always updated, the bad place of course to be corrected, getch () added at the end of the program, it does not assign value to any variable, so it is in this place is completely garbage code, unrelated to the program. Taking this into account in C + +, so every time the program runs out, it automatically stops the screen, and displays "Press any key ..." to call you to push any key to exit, which is like C + + in its environment to run the program, at the end of the program automatically add a line of getch (); And before this line statement also added a line of output statements cout<< "Press any key ..." to prompt you to end the program, pressing any key to continue.

Getche () and Getch () are similar, it also needs to introduce header file Conio.h, what is the difference between them? The difference is that getch () has no return display, Getche () has a return display.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.