Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Vaild pause?

Vaild pause?

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark 0
    wrote on last edited by
    #1

    Real quick: Is this a valid way to pause a consle program?

    cout<< "Press ENTER to continue..."; //Informs the user what is happening
    cin.ignore(); //clears the cinstream of any stray characters
    cin.get(); //pauses until user presses ENTER

    I have heard that you want to avoid system calls like system("pause");, so is this a viable option? Thanks -Mark


    We're sorry, we were unable to complete you request. The website administrator has been automatically notified. REFRESH?


    ¥492077616E74206120726566756E6400¥

    R J 2 Replies Last reply
    0
    • M Mark 0

      Real quick: Is this a valid way to pause a consle program?

      cout<< "Press ENTER to continue..."; //Informs the user what is happening
      cin.ignore(); //clears the cinstream of any stray characters
      cin.get(); //pauses until user presses ENTER

      I have heard that you want to avoid system calls like system("pause");, so is this a viable option? Thanks -Mark


      We're sorry, we were unable to complete you request. The website administrator has been automatically notified. REFRESH?


      ¥492077616E74206120726566756E6400¥

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      You could try using Sleep() or simply loop until the requisite number of seconds have elapsed.

      int nElapsed = 0;
      int nWaitFor = 5; // wait 5 seconds
      time_t tmStart;

      time (&tmStart);
      do {
      time_t tmNow;
      time (&tmNow);
      nElapsed = tmNow - tmStart;
      } while (nElapsed < nWaitFor);

      /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

      M 1 Reply Last reply
      0
      • M Mark 0

        Real quick: Is this a valid way to pause a consle program?

        cout<< "Press ENTER to continue..."; //Informs the user what is happening
        cin.ignore(); //clears the cinstream of any stray characters
        cin.get(); //pauses until user presses ENTER

        I have heard that you want to avoid system calls like system("pause");, so is this a viable option? Thanks -Mark


        We're sorry, we were unable to complete you request. The website administrator has been automatically notified. REFRESH?


        ¥492077616E74206120726566756E6400¥

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #3

        system() is almost always a bad choice. :) -- My name in Katakana is ヨルゲン. My name in German is Jörgen. I blog too now[^]

        1 Reply Last reply
        0
        • R Ravi Bhavnani

          You could try using Sleep() or simply loop until the requisite number of seconds have elapsed.

          int nElapsed = 0;
          int nWaitFor = 5; // wait 5 seconds
          time_t tmStart;

          time (&tmStart);
          do {
          time_t tmNow;
          time (&tmNow);
          nElapsed = tmNow - tmStart;
          } while (nElapsed < nWaitFor);

          /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

          M Offline
          M Offline
          Mark 0
          wrote on last edited by
          #4

          What if I want to wait for user input? Different people take a different amount time to read and understand the same info. Make the time too short and the user gets pissed off b/c they missed something, too long and they sit there pounding to keyboard trying to progress in the program. -Mark


          We're sorry, we were unable to complete you request. The website administrator has been automatically notified. REFRESH?


          ¥492077616E74206120726566756E6400¥

          R 1 Reply Last reply
          0
          • M Mark 0

            What if I want to wait for user input? Different people take a different amount time to read and understand the same info. Make the time too short and the user gets pissed off b/c they missed something, too long and they sit there pounding to keyboard trying to progress in the program. -Mark


            We're sorry, we were unable to complete you request. The website administrator has been automatically notified. REFRESH?


            ¥492077616E74206120726566756E6400¥

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            ---Mark--- wrote: What if I want to wait for user input? You don't have to do anything special to wait for user input. cin >> foo won't complete until the user presses Enter. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

            M 1 Reply Last reply
            0
            • R Ravi Bhavnani

              ---Mark--- wrote: What if I want to wait for user input? You don't have to do anything special to wait for user input. cin >> foo won't complete until the user presses Enter. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

              M Offline
              M Offline
              Mark 0
              wrote on last edited by
              #6

              Maybe that was confusing. I didn't mean actual input like a number or character, I meant to wait for the user to acknowledge that what is being displayed on the console has been read and the program can progress or end. In that case is the way I mentioned a good way to do that or are there better? Thanks -Mark


              We're sorry, we were unable to complete you request. The website administrator has been automatically notified. REFRESH?


              ¥492077616E74206120726566756E6400¥

              R 1 Reply Last reply
              0
              • M Mark 0

                Maybe that was confusing. I didn't mean actual input like a number or character, I meant to wait for the user to acknowledge that what is being displayed on the console has been read and the program can progress or end. In that case is the way I mentioned a good way to do that or are there better? Thanks -Mark


                We're sorry, we were unable to complete you request. The website administrator has been automatically notified. REFRESH?


                ¥492077616E74206120726566756E6400¥

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #7

                Ah, gotcha. I don't know you'd do that in a console program without resorting to assembly programming. I did something similar decades ago on a VMS system - my function waited for user input for upto "n" seconds. This kind of stuff is easy to do in a GUI Windows app. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups