Thread: Another simple question

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    51

    Another simple question

    Hi,

    Let say I printed something out to the screen,

    cout << "Love one another";

    how do I make it so that so the program will pause until the user hits "enter"??

    Is there some Pause, Wait command??
    Which is the master, which is the student?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    cout << "Love one another";
    cin.get();

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    I think the prelude is very nice...no pun intended
    Which is the master, which is the student?

  4. #4
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    ...........

    getch(); // waits for any key being pressed

    ............

    #include <stdlib.h>

    system("pause");

    // print to the screen "Press any key to continue..." and waits for user's input....
    ..................

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >getch(); // waits for any key being pressed
    Nonstandard, may not work on all implementations and a bad idea in general to use unless you have to.

    >system("pause");
    To my knowledge this only works on DOS and Windows systems, and the system function is godawful slow.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    2
    while (!kbhit()); should also work, but I believe it's nonstandard as well.

    BTW getch() will continue if the user presses any key at all. To check for enter being pressed, try:

    while (getch() != 13);

  7. #7
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    Here's a standard way...


    Code:
    char wait;
    cin>>wait;

    The fastest too

  8. #8
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Yeah but you could gunk up your buffer doing that.

  9. #9
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    I love this forum, ...thank you to everyone who replied, appreciate the advice and suggestions
    Which is the master, which is the student?

  10. #10
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    another quick question:

    I don't remember exactly, but once upon a time I heard that "cout" outputs to a buffer. I was wonder if there is a command to purge that buffer (i.e. to display the text in that buffer immediately). I'm having timing problems with the getin() and system("pause").

    cout << "WASABI";
    getin() // or system(pause)

    my program would pause first, then when i press enter,..."WASABI" would then print (not good :[)
    Which is the master, which is the student?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM