Thread: conio.h, getch(), getche()

  1. #1
    Registered User
    Join Date
    Mar 2011

    conio.h, getch(), getche()


    I found the following code (which I've changed a bit) and the explanation in blue in a book. I don't understand the use of getch() or other function getche() the book refers to. Could you please comment on this? And what does "\r" stands for? Thanks for all the help.

    One function in EXTERN, getachar(), reads characters from the keyboard. It uses the library function getch(), which is like getche() except that it doesnít echo the character typed to the screen (hence the absence of the final e in the name). A second EXTERN function, putachar(), displays each character on the screen. The effect is that what you type is displayed in the normal way:
    Iím typing in this line of text

    // extern.cpp
    // demonstrates global variables
    #include <iostream>
    #include <cstdlib>
    #include <conio.h>        //for getch()
    using namespace std;
    char ch = 'a';            //global variable ch
    void getachar();          //function declarations
    void putachar();
    int main()
           cout << "ch is: " << ch << endl;
       while( ch != '\r' )    //main() accesses ch
       cout << endl;
       return 0;
    void getachar()           //getachar() accesses ch
       ch = getch();
    void putachar()           //putachar() accesses ch
       cout << ch;
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    Registered User
    Join Date
    May 2011
    conio.h is obselete. Use iostream and cstlib instead, which you already appear to have included... cin.get() > system("pause").

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hi.....getche()
    By makiboy in forum C Programming
    Replies: 2
    Last Post: 10-07-2008, 08:53 AM
  2. getch() / getche()
    By Blanket in forum C++ Programming
    Replies: 5
    Last Post: 04-27-2003, 07:06 PM
  3. Replies: 0
    Last Post: 11-01-2002, 11:56 AM
  4. conio.c and getch() conflict?
    By Nutshell in forum C Programming
    Replies: 5
    Last Post: 10-12-2002, 01:01 AM
  5. differences between getch(), getche(), and ungetch()
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 01-08-2002, 02:08 AM