SRL Archive - C/C++ Help and Tutorials

Is there a wait option in C++?


Rs-Gp-4U

2008-03-02 06:47:23

(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

2008-03-02 06:59:44

try

Sleep(1000); works for delphi, i got that from markus 10 mins ago xD

Rs-Gp-4U

2008-03-02 07:01:57

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

2008-03-02 07:03:08

for delphi not

Rs-Gp-4U

2008-03-02 07:05:13

I'm on about c++ mate

ShowerThoughts

2008-03-02 07:33:24

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

2008-03-02 07:48:43

Thanks hermpie ++!

mastaraymond

2008-03-02 07:55:22

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

2008-03-02 09:50:01

try including <time.h> and using "time()" and do mastaraymond's solution

look in a C standard library for a better explaination

foolishpaper

2008-03-03 01:16:35

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

2008-03-03 22:55:23

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

2008-03-04 14:31:38

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

2008-03-06 15:06:31

[PHP]
#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;
}[/PHP]

Rs-Gp-4U

2008-03-06 16:01:28

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