View Full Version : Is there a wait option in C++?
Rs-Gp-4U
03-02-2008, 11:47 AM
(As title says) , and if so what is it, and do i need a include package?
For e.g wait(1000);
Reply a.s.a.p PLEASE
ShowerThoughts
03-02-2008, 11:59 AM
try
Sleep(1000); works for delphi, i got that from markus 10 mins ago xD
Rs-Gp-4U
03-02-2008, 12:01 PM
Hmm i'll try i don't know if i forgot to capilize the "s" before because C++ is a really sensitive language, thanks though, does it not need a #include <>?
ShowerThoughts
03-02-2008, 12:03 PM
for delphi not
Rs-Gp-4U
03-02-2008, 12:05 PM
I'm on about c++ mate
ShowerThoughts
03-02-2008, 12:33 PM
i know already tested? but c++ and delphi for what i've seen have some same stuff so? works? i'm not amazed if it's not xD
Rs-Gp-4U
03-02-2008, 12:48 PM
Thanks hermpie ++!
mastaraymond
03-02-2008, 12:55 PM
Just make a loop that waits till a certain moment and let it process the messages...
In delphi it would be like:
Time := GetSystemTime + WaitTime;
While GetSystemtime < Time do
GetApplication.processmessages;
Yakman
03-02-2008, 02:50 PM
try including <time.h> and using "time()" and do mastaraymond's solution
look in a C standard library for a better explaination
foolishpaper
03-03-2008, 06:16 AM
You can use a void function. Try this. (the // are just comments)
#include <iostream>
#include <ctime> //need for time
using namespace std;
void wait_time();
void wait_time1();
int main()
{
cout << "Please wait 3 seconds\n\n";
wait_time();
cout << "Type 'y' to continue\n\n";
char yes;
cin >> yes;
if (yes = 'y')
{
cout << "Please wait 5 seconds\n\n";
wait_time();
cout << "The end! Hope that helped!"
}
return 0;
}
void wait_time() //waits three seconds
{
clock_t delay = 3 * CLOCKS_PER_SEC; // convert to clock ticks
clock_t start = clock();
while (clock() - start < delay )
;
}
void wait_time1() //waits 5 secs
{
clock_t delay = 5 * CLOCKS_PER_SEC; // convert to clock ticks
clock_t start = clock();
while (clock() - start < delay )
;
}
R0b0t1
03-04-2008, 03:55 AM
I thought that sleep worked for C++ also... Maybe thats only VB.
Why would you be waiting? I would just call an empty procedure called 'donull' repeatedly until the condition was met... Or not.
=\. You've maid me interested.
Rs-Gp-4U
03-04-2008, 07:31 PM
Robot ive decided to make a FAKE virus lol so i want it to like wait 2 second before it says another percentage..
Heres the code..
#include <iostream>
#include <time.h>
using namespace std;
void sleep();
{
int main()
{
cout << "Downloading.. 1% of virus" << endl;
Sleep(1000);
cout << "Downloading.. 4% of virus" << endl;
Sleep(1000);
Sleep << "Downloading.. 7% of virus" << endl;
Sleep(1000);
cout << "Downloading.. 11% of virus" << endl;
Sleep(1000);
cout << "Downloading.. 13% of virus" << endl;
Sleep(1000);
cout << "Downloading.. 15% of virus" << endl;
Sleep(1000);
cout << "Downloading.. 18% of virus" << endl;
Sleep(1000);
cout << "Downloading.. 19% of virus" << endl;
Sleep(1000);
cout << "Downloading.. 21% of virus" << endl;
Sleep(1000);
cout << "Downloading.. 24% of virus" << endl;
system("PAUSE");
}
}
But i get 2 errors..
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Documents and Settings\Presario\Desktop\C++\Virus.cpp" -o "C:\Documents and Settings\Presario\Desktop\C++\Virus.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Presario\Desktop\C++\Virus.cpp:2:19: ctime.h: No such file or directory
C:\Documents and Settings\Presario\Desktop\C++\Virus.cpp:6: error: expected unqualified-id before '{' token
C:\Documents and Settings\Presario\Desktop\C++\Virus.cpp:6: error: expected `,' or `;' before '{' token
Execution terminated
Please help asap need all the C++ professors :)
Negaal
03-06-2008, 08:06 PM
#include <iostream>
using namespace std;
void wait(int time)
{
clock_t delay = time * CLOCKS_PER_SEC;
clock_t start = clock();
while (clock() - start < delay );
}
int main()
{
for(int i=0; i<=100; i+=2)
{
system ("cls");
cout << "Downloading... " << i << "% of virus \n";
}
wait(3);
cout << "Download complete, now rebooting \n";
wait(3);
cout << "Haha R.I.P. \n";
system("PAUSE");
return 0;
}
Rs-Gp-4U
03-06-2008, 09:01 PM
thanks ne.. but ive gt sleep working.. you need to include window.h could be windows writing this on psp so cnt mmbr nd u pt sleep(1000); THANKS NE FOR THE LOOP CS I HAVNT LEARNED THEM YET
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.