
-----------------------------------
infernomaster
Thu Sep 11, 2003 8:09 am

Newbie Question!
-----------------------------------
Well I've been studying Comsci for 3 years now and just switch from turing to c++...
I was wondering what is the code for delaying before clearing the screen?

In turing:
delay(sec);
cls;

then what is this in visual c++??

-----------------------------------
octopi
Thu Sep 11, 2003 8:29 am


-----------------------------------
This is a yucky solution....but it works.


#include 
#include 

int main(int argc, char* argv[])
{
    printf("Hello World!\n");
    Sleep(2000);
    system("cls"); 
    return 0;
}

-----------------------------------
Tony
Thu Sep 11, 2003 4:30 pm


-----------------------------------
This is a yucky solution....

yeah, Sleep is no good since it suspends the whole program, and it would be frozen till time elapses.

In VB, I prefer to use a loop with timer and DoEvents, but I'm not sure of C++ equivalent.

-----------------------------------
octopi
Thu Sep 11, 2003 4:44 pm


-----------------------------------
I didn't think there was anything wrong with the Sleep function
I was refering to the use of system to clear the screen....thats the ucky part.

I think tony's thinking of a GUI program or something...but the original person said they wanted to use a clearscreen command like in turing, so that would mean they are using a console in c++

-----------------------------------
Dan
Thu Sep 11, 2003 6:30 pm


-----------------------------------
in the worads of some you who thougth me some stuff about c++, "DONT USE THE SYSTEM COMAND!!!! (it blows up masheines)".

well it may not blow up your comp but it is relay bad when trying to make protable progames. if you know what you are doing it can be used right but will likey bring up isuses when you try to run it on difrent kinds of computers.

-----------------------------------
Andy
Mon Sep 15, 2003 6:49 pm


-----------------------------------
so how DO you delay a program in c++ anyhow? and is there a clear screen function that doesnt f*** up your system?

-----------------------------------
octopi
Mon Sep 15, 2003 7:05 pm


-----------------------------------
If you are making a console program for windows then use the code I posted...it will work 100% of the time.

If you want to delay and clear on unix then you will need to use a different method.


In 'C++' there is no portable way to clear the screen. It is all platform dependant.

I am pretty sure the same goes for the delay thing too.


Using `system` is the best, and easiest way to clear the screen. You can use it to clear the screen on windows and unix (cls on win, clear on unix)

-----------------------------------
Andy
Mon Sep 15, 2003 7:12 pm


-----------------------------------
then why did dan say it f***s up ur comp?
and i dont want sleep, is there a different method?

-----------------------------------
octopi
Mon Sep 15, 2003 7:13 pm


-----------------------------------
Whats wrong with sleep?

Dan said it...because your replying on external commands.....except cls is built into windows, and not an external command, so it doesn't really apply.

-----------------------------------
Andy
Mon Sep 15, 2003 7:16 pm


-----------------------------------
wel... when u fork something, sleep will screw it up wont it?

-----------------------------------
octopi
Mon Sep 15, 2003 7:21 pm


-----------------------------------
Well if your fork something then you make a new process, and so Sleep wouldn't affect it, cause all it does is this:
Process A: contains the sleep function
Process B: another program/process on the computer

Process A sleeps -> tells os to give its timeshare of the cpu to another process. -> Process B gets processed during the free time that Process A gave up.

-----------------------------------
Andy
Mon Sep 15, 2003 7:26 pm


-----------------------------------
but... didnt tony say it freezes up the whole program? until the timelimit us up?

-----------------------------------
Tony
Mon Sep 15, 2003 8:07 pm


-----------------------------------
I suppose it depends on the language/compiler...

You just gotta try and see.

-----------------------------------
jonos
Thu Feb 12, 2004 10:13 pm


-----------------------------------
does anyone know if devc++ has problems with the Sleep function because its not working on mine.

-----------------------------------
Dan
Fri Feb 13, 2004 7:47 pm


-----------------------------------
wow u are bring up an old post.

but why not make your own sleep fuction by making a while loop that keeps on going in till x amout of time has passed. u can figger out how much time has passed by using the time comands (i hope thous are not platform spifick).
