Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Newbie Question!
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
infernomaster




PostPosted: 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
Sponsor
sponsor
octopi




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
octopi




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
octopi




PostPosted: 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




PostPosted: Mon Sep 15, 2003 7:16 pm   Post subject: (No subject)

wel... when u fork something, sleep will screw it up wont it?
octopi




PostPosted: 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




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
jonos




PostPosted: 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




PostPosted: 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!
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: