getch()

This is a discussion on getch() within the C++ Programming forums, part of the General Programming Boards category; If i have a program where it asks "Press space to continue " How can I do it ? I ...

  1. #1
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    Unhappy getch()

    If i have a program where it asks "Press space to continue "
    How can I do it ? I have seen it done like that before, like "char a=getch()" or something like that. Sorry for being so vague
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  2. #2
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Code:
    cout << "Press any key to continue";
    cin.get();
    
    // or
    
    cout << "Press any key to continue";
    char a = getch();
    If you're using getch make sure you include conio.h
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Use getchar( ) don't use getch( ) because its not ANSI standard.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Originally posted by MrWizard
    Use getchar( ) don't use getch( ) because its not ANSI standard.
    What library to use?
    none...

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Its included in standard input/output (stdio.h)

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I think that in MVSC it is included with the standard library.

  8. #8
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    Unhappy thanks, but no thanks

    Of course I know how to pause, but I mean if you want the program only to continue if the user hits a specific key. Or only does a specific task if that key is entered. I know I could use a switch statement, or if(a=='H') but what if I need only space.

    Example
    (i don't know how to use code tags, so hammer go ahead and go crazy)

    cout << "Hit space to fire";
    ?????????? // don't know what to hit here

    BTW, how does getchar work, because I like to keep with standards
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  2. Pls repair my basketball program
    By death_messiah12 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2006, 05:15 AM
  3. Pause a C program without getch()
    By swgh in forum C Programming
    Replies: 4
    Last Post: 02-20-2006, 11:24 AM
  4. Clearing input buffer after using getch()
    By milkydoo in forum C++ Programming
    Replies: 3
    Last Post: 07-22-2003, 12:04 AM
  5. Problems with getch()
    By GrNxxDaY in forum C++ Programming
    Replies: 14
    Last Post: 08-12-2002, 03:11 AM

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