Thread: Basic question - press any key to continue

  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, 11:16 AM
  2. Need help: wait for key press
    By Pan in forum C++ Programming
    Replies: 4
    Last Post: 04-11-2006, 12: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, 10:45 PM
  5. Replies: 1
    Last Post: 10-07-2001, 12:27 AM