Basic question - press any key to continue

This is a discussion on Basic question - press any key to continue within the C++ Programming forums, part of the General Programming Boards category; A basic c++ question. In a console aplication, how do i wait for any key to be pressed? like: Code: ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    42

    Basic question - press any key to continue

    A basic c++ question.
    In a console aplication, how do i wait for any key to be pressed?

    like:
    Code:
    cout<<"press any key to continue"<<endl;
    ???what should i put here???

  2. #2
    *this
    Join Date
    Mar 2005
    Posts
    498
    well you could include <conio.h> i think, then use the function getch();
    or you could say "press enter to continue" and use cin.get();

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    42
    working perfectly.
    thanks

  4. #4
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    or you could use

    system("pause");

    instead of the cout<<"press any key to continue"<<endl;
    ???what should i put here???

    it would save a lot of time if you use it a lot but some people say that its a curse if you use it, i really dont see why its so bad.
    Keyboard Not Found! Press any key to continue. . .

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by DeepFyre
    or you could use
    it would save a lot of time if you use it a lot but some people say that its a curse if you use it, i really dont see why its so bad.
    1)pause is a program which is part of Microsoft windows and MS-DOS, compile you're program in another environment and it will fail, cin.get() is portable.
    2)The system command is slow because it's calling an external program.
    3)It's insecure because somone could tamper with the pause command (or create a command with the same name in the local directory, depending on what the search order is)and that program would run with the privilages of your program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [HELP] key press
    By Dakaa in forum C Programming
    Replies: 6
    Last Post: 05-30-2009, 12:16 PM
  2. Need help: wait for key press
    By Pan in forum C++ Programming
    Replies: 4
    Last Post: 04-11-2006, 01:26 AM
  3. Press Any Key Two Continue
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 02-02-2002, 09:24 PM
  4. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 11:45 PM
  5. Replies: 1
    Last Post: 10-07-2001, 01:27 AM

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