| | |
Pause the Program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
How would you make the program pause for a certain amount of time? I can't just tell it to do some trivial task over and over for so many loops, because the compiler seems to know its trivial and cuts it out. There's gotta be a simpler way anyway.
First function takes amount of seconds so for example
sleep(1) will pause your program for one second, and the usleep uses microsecond usleep(1000000) will pause the prog for one second. If you want to win, you must not loose (Alan Ford)
If you are using Windows and Dev-C++ then the function is Sleep(milliseconds) ...
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <iostream> #include <windows.h> // needed for Sleep(millisec) using namespace std; int main(int argc, char *argv[]) { cout << "start..." << endl; Sleep(2000); cout << "done..." << endl; system("PAUSE"); return EXIT_SUCCESS; }
May 'the Google' be with you!
If you ever used Dev-C++ you would know that much of this code comes up as a templet. My point was to show how to use the Sleep() function. Talking about heavy overhead, the iostream header creates about 95% of the overhead.
May 'the Google' be with you!
My post was not meant to contradict or show you wrong, just to point to the OP not to use the system functions when the same thing can be done using the std library functions.
This will be useful when he wants to write normal programs not involving "windows" specific code and needs the pause functinality.
which cant be avoided when you are all set to write some concrete code snippets.
This will be useful when he wants to write normal programs not involving "windows" specific code and needs the pause functinality.
•
•
•
•
Talking about heavy overhead, the iostream header creates about 95% of the overhead.
Last edited by ~s.o.s~; Oct 2nd, 2006 at 1:35 pm.
I don't accept change; I don't deserve to live.
I agree with you, cin.get() is the portable way to wait, but take a look at a small code snippet I wrote a long time ago:
http://www.daniweb.com/code/snippet105.html
I would love, if you could explain to me why cin.get() is such a flop in this fairly simple case.
http://www.daniweb.com/code/snippet105.html
I would love, if you could explain to me why cin.get() is such a flop in this fairly simple case.
May 'the Google' be with you!
•
•
•
•
I agree with you, cin.get() is the portable way to wait, but take a look at a small code snippet I wrote a long time ago:
http://www.daniweb.com/code/snippet105.html
I would love, if you could explain to me why cin.get() is such a flop in this fairly simple case.
•
•
•
•
I would love, if you could explain to me why cin.get() is such a flop in this fairly simple case.
Just append the stmts:
C++ Syntax (Toggle Plain Text)
cin.clear(); cin.ignore(std::numeric_limits<streamsize>::max(),'\n');
cin.get () and everything should work out to be fine without that nasty "system" call which kills the so much loved portability.Maybe you would want to take a look here:
http://www.augustcouncil.com/~tgibson/tutorial/iotips.html
Hope it helped, bye.
Last edited by ~s.o.s~; Oct 2nd, 2006 at 2:41 pm.
I don't accept change; I don't deserve to live.
Great, thanks ~s.o.s~ I finally was able to get rid of the old eyesore system("pause"). I knew there were stray '\n' around, but even the old double cin.get() trick didn't work here. Strangely enough, Narue mentioned that very same solution in another context. Should have listened and connected the dots
The "Enter some floating point numbers (q to quit)\n" part is not a feature, sometimes I just give up on foolproving things. I guess I never just pressed q or enter. C++ obviously doesn't like to process a totally empty vector. What would you recommend?
Thanks for the help and your interest!
The "Enter some floating point numbers (q to quit)\n" part is not a feature, sometimes I just give up on foolproving things. I guess I never just pressed q or enter. C++ obviously doesn't like to process a totally empty vector. What would you recommend?
Thanks for the help and your interest!
May 'the Google' be with you!
![]() |
Similar Threads
- Pausing program with getchar(); (C)
- system("pause"); (C++)
- Old School Compiler vs New Compiler (C++)
- How to code a program that can show color text output??? (C)
- Problem with validation in c (C++)
- How to code a program that can play sound (C++)
- How do I pause a Prorgam? (C++)
- Error message when I run my program in C++ (C++)
- Round Robin algorithm? (Java)
Other Threads in the C++ Forum
- Previous Thread: Got the C++, what now?
- Next Thread: Implementing C++ into applications
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






