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.
LieAfterLie
10
Light Poster
Recommended Answers
Jump to PostOS and Compiler?
Jump to PostHow 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.
Try …
Jump to PostIf you are using Windows and Dev-C++ then the function is Sleep(milliseconds) ...
#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; }
Jump to PostBetter not call the "system" functions like
system ("pause")
.Your job can be very well done using the function
cin.get()
which does the same function without invoking the system procedures which incur heavy overheads.
All 16 Replies
Grunt
19
Junior Poster
andor
25
Posting Whiz in Training
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster

iamthwee
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
LieAfterLie
10
Light Poster
aeinstein
commented:
Always nice to see someone post how there issue was resolved.
+10
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.