I have been asked to add a pause to an existing C++ program.
They do not want to use the Windows builtin scheduler for reasons they won't share with me.
Is the correct way of doing this something like:-
void Sleep(10000);
Need to add pause to existing C++ programNeed to add pause to existing C++ program
Page 1 of 1
9 Replies - 2645 Views - Last Post: 17 July 2009 - 05:28 PM
Replies To: Need to add pause to existing C++ program
#2
Re: Need to add pause to existing C++ program
Posted 17 July 2009 - 03:23 AM
NOPE. . .
your teacher doesnt want you to use
system Commands
Try using
or
but its much better to you cin.get();
have a look at this post
http://www.dreaminco...wtopic30581.htm
Hope this helps
Kevin
your teacher doesnt want you to use
system Commands
system("pause");
Try using
cin.get()
or
#include "conio.h" _getch();
but its much better to you cin.get();
have a look at this post
http://www.dreaminco...wtopic30581.htm
Hope this helps
Kevin
This post has been edited by deery5000: 17 July 2009 - 03:26 AM
#3
Re: Need to add pause to existing C++ program
Posted 17 July 2009 - 04:07 AM
deery5000, on 17 Jul, 2009 - 02:23 AM, said:
NOPE. . .
your teacher doesnt want you to use
system Commands
Try using
or
but its much better to you cin.get();
have a look at this post
http://www.dreaminco...wtopic30581.htm
Hope this helps
Kevin
your teacher doesnt want you to use
system Commands
system("pause");
Try using
cin.get()
or
#include "conio.h" _getch();
but its much better to you cin.get();
have a look at this post
http://www.dreaminco...wtopic30581.htm
Hope this helps
Kevin
I am afraid that my question was not clear enough.
We need the program to stop running for a period of time and when that time has elapsed carry on running.
That was why I suggested sleep().
#4
Re: Need to add pause to existing C++ program
Posted 17 July 2009 - 04:52 AM
straygrey, on 17 Jul, 2009 - 01:39 AM, said:
I have been asked to add a pause to an existing C++ program.
They do not want to use the Windows builtin scheduler for reasons they won't share with me.
Is the correct way of doing this something like:-
void Sleep(10000);
They do not want to use the Windows builtin scheduler for reasons they won't share with me.
Is the correct way of doing this something like:-
void Sleep(10000);
DON'T use:
include <windows.h>
Sleep(5000);
#5
Re: Need to add pause to existing C++ program
Posted 17 July 2009 - 07:46 AM
A nice explanation as to why would be nice.
#6
Re: Need to add pause to existing C++ program
Posted 17 July 2009 - 07:52 AM
sleep is resource heavy, it calls into the system( i think) or at least a wrapper for it. Otherwords, it is not standard c++ .this is the best way i know how to do this :
#include <ctime>
void timer(double seconds)
{
clock_t x;
x=clock()+seconds*CLOCKS_PER_SEC;
while(clock()<x){}
}
This post has been edited by ImaSexy: 17 July 2009 - 07:54 AM
#7
Re: Need to add pause to existing C++ program
Posted 17 July 2009 - 12:31 PM
int count = 1; while (count <= 1000) count++;
#8
Re: Need to add pause to existing C++ program
Posted 17 July 2009 - 12:37 PM
ImaSexy, on 17 Jul, 2009 - 06:52 AM, said:
sleep is resource heavy, it calls into the system( i think) or at least a wrapper for it. Otherwords, it is not standard c++ .this is the best way i know how to do this :
#include <ctime>
void timer(double seconds)
{
clock_t x;
x=clock()+seconds*CLOCKS_PER_SEC;
while(clock()<x){}
}
what?
listen what you're saying
1) Sleep is just pausing current thread, this means it uses maximumly 1% of processor while your code tries to execute so fast as it can.. making processor 100%
Sleep doesnt have anything to do with system(), i think you have gotten somewhere wrong, the most inefficient way to sleep is just exact way you showed.
#9
Re: Need to add pause to existing C++ program
Posted 17 July 2009 - 02:56 PM
What I used to do to temporarily pause it was just input a character with the same kind of message it would give you from a Microsoft compiler:
char pause()
{
char c;
cout << "\nPlease press a button and then hit <Enter>: ";
cin >> c;
//return the character pressed incase it is useful:
return c;
}
#10
Re: Need to add pause to existing C++ program
Posted 17 July 2009 - 05:28 PM
oh my bad, sorry im not used to using it. But i know that sleep() is ok, but Sleep() is alright too but it is not standard c++
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|