conio.h, getch(), getche()

This is a discussion on conio.h, getch(), getche() within the C++ Programming forums, part of the General Programming Boards category; Hi I found the following code (which I've changed a bit) and the explanation in blue in a book. I ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    conio.h, getch(), getche()

    Hi

    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


    Code:
    // 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
          {
          getachar();
          putachar();
          }
    
       cout << endl;
    
       system("pause");
    
       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
    Posts
    30
    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, 09:53 AM
  2. getch() / getche()
    By Blanket in forum C++ Programming
    Replies: 5
    Last Post: 04-27-2003, 08: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, 02: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21