Author |
Message |
infernomaster
|
Posted: Thu Sep 11, 2003 8:09 am Post subject: 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++?? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
octopi
|
Posted: Thu Sep 11, 2003 8:29 am Post subject: (No subject) |
|
|
This is a yucky solution....but it works.
code: | #include <stdlib.h>
#include <windows.h>
int main(int argc, char* argv[])
{
printf("Hello World!\n");
Sleep(2000);
system("cls");
return 0;
} |
|
|
|
|
|
|
Tony
|
Posted: Thu Sep 11, 2003 4:30 pm Post subject: (No subject) |
|
|
octopi wrote: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
octopi
|
Posted: Thu Sep 11, 2003 4:44 pm Post subject: (No subject) |
|
|
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
|
Posted: Thu Sep 11, 2003 6:30 pm Post subject: (No subject) |
|
|
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. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
Andy
|
Posted: Mon Sep 15, 2003 6:49 pm Post subject: (No subject) |
|
|
so how DO you delay a program in c++ anyhow? and is there a clear screen function that doesnt f*** up your system? |
|
|
|
|
|
octopi
|
Posted: Mon Sep 15, 2003 7:05 pm Post subject: (No subject) |
|
|
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
|
Posted: Mon Sep 15, 2003 7:12 pm Post subject: (No subject) |
|
|
then why did dan say it f***s up ur comp?
and i dont want sleep, is there a different method? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
octopi
|
Posted: Mon Sep 15, 2003 7:13 pm Post subject: (No subject) |
|
|
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
|
Posted: Mon Sep 15, 2003 7:16 pm Post subject: (No subject) |
|
|
wel... when u fork something, sleep will screw it up wont it? |
|
|
|
|
|
octopi
|
Posted: Mon Sep 15, 2003 7:21 pm Post subject: (No subject) |
|
|
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
|
Posted: Mon Sep 15, 2003 7:26 pm Post subject: (No subject) |
|
|
but... didnt tony say it freezes up the whole program? until the timelimit us up? |
|
|
|
|
|
Tony
|
Posted: Mon Sep 15, 2003 8:07 pm Post subject: (No subject) |
|
|
I suppose it depends on the language/compiler...
You just gotta try and see. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
jonos
|
Posted: Thu Feb 12, 2004 10:13 pm Post subject: (No subject) |
|
|
does anyone know if devc++ has problems with the Sleep function because its not working on mine. |
|
|
|
|
|
Dan
|
Posted: Fri Feb 13, 2004 7:47 pm Post subject: (No subject) |
|
|
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). |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
|