View previous topic :: View next topic |
Author |
Message |
Engineer Expert Cheater
Reputation: 1
Joined: 25 Nov 2007 Posts: 170
|
Posted: Fri Jan 04, 2008 11:58 am Post subject: Two tiny c++ questions |
|
|
Is there a command to clean cmd\dos screen?
How do i make a looping function that repeats every 1 second?
thanks...
|
|
Back to top |
|
 |
the_undead Expert Cheater
Reputation: 1
Joined: 12 Nov 2006 Posts: 235 Location: Johannesburg, South Africa
|
Posted: Fri Jan 04, 2008 12:18 pm Post subject: |
|
|
hers a function that Ive used before:
Code: | void ClearScreen()
{
HANDLE hSTD = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordinates = {0,0};
CONSOLE_SCREEN_BUFFER_INFO buffer_info;
GetConsoleScreenBufferInfo(hSTD, &buffer_info);
FillConsoleOutputCharacter(hSTD, ' ', buffer_info.dwSize.X * buffer_info.dwSize.Y, coordinates, NULL);
SetConsoleCursorPosition(hSTD, coordinates);
} |
I've had it sitting in a folder for so long I cant remember if I wrote it or someone else did...
as for the loop, you could either use a timer or you could use a timer and just sleep but if you go for the latter, you might wanna do it in a different thread (I dunno, depends on what you want).
_________________
|
|
Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri Jan 04, 2008 12:30 pm Post subject: |
|
|
Can't you use System("cls");? I don't know much C++, I remember when I used System it was like batch... System("echo ..."); and System("Pause"); so I guess cls will work too.
|
|
Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Fri Jan 04, 2008 12:33 pm Post subject: Re: Two tiny c++ questions |
|
|
ZzOoZz wrote: | How do i make a looping function that repeats every 1 second? |
What do you want it to do?
If it does nothing
Code: |
for ( ; ; ) //never ending
{
Sleep(1000); //pause for a second--I think that's how you do it
}
|
_________________
Last edited by samuri25404 on Sat Jan 05, 2008 7:24 am; edited 1 time in total |
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Jan 04, 2008 6:36 pm Post subject: |
|
|
Use a while statement instead of an endless for loop. Have the condition a toggled boolean or something of the sort so it has an escape method and doesn't just get stuck in memory. (Just a suggestion.)
@Sam: Yea you can use System("cls") most don't use the System() command though due to overhead and sloppy methods. If you google pros and cons of System() you should find some interesting reads about how it creates a lot of overhead for simple tasks such as cls.
_________________
- Retired. |
|
Back to top |
|
 |
Engineer Expert Cheater
Reputation: 1
Joined: 25 Nov 2007 Posts: 170
|
Posted: Sat Jan 05, 2008 6:34 am Post subject: Re: Two tiny c++ questions |
|
|
[quote="samuri25404"][quote="ZzOoZz"]How do i make a looping function that repeats every 1 second? Quote: |
What do you want it to do?
If it does nothing
Code: |
for ( ; ; ) //never ending
{
Sleep(1000); //pause for a second--I think that's how you do it
}
|
|
its not working. my compliler says sleep() isnt a function
|
|
Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sat Jan 05, 2008 6:41 am Post subject: |
|
|
I think you need to include "dos" or "dos.h"... and try sleep, maybe its case sensetive.
|
|
Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sat Jan 05, 2008 7:02 am Post subject: |
|
|
Symbol wrote: | I think you need to include "dos" or "dos.h"... and try sleep, maybe its case sensetive. |
unistd.h
Sleep(10);
|
|
Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Sat Jan 05, 2008 7:42 am Post subject: |
|
|
Quote: | its not working. my compliler says sleep() isnt a function |
#include Windows.h
http://msdn2.microsoft.com/en-us/library/ms686298.aspx
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
Back to top |
|
 |
|