Jump to content
  • Advertisement
Sign in to follow this  
Fifty-Five

Time and Clear Screen

This topic is 4417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, this is my first post in the forums. I've been doing some basic C++ programming and was wondering if anyone could answer some questions. Does anyone know of any c++ commands to clear the screen in a basic text application? I'm also trying to find information on the the uses of time and delays within text applications, such as making the screen wait several seconds before displaying a readout or cout line, etc. Any links or advice would be much appreciated. If these questions arent clear enough to illicit a response, please contact me and I'll try to clarify.

Share this post


Link to post
Share on other sites
Advertisement
for clearing the screen you can use this command

system("cls");

its dos command but it works just fine =)
(dont forget to include stdlib.h

Share this post


Link to post
Share on other sites
Quote:
Original post by Fifty-Five
Hello, this is my first post in the forums. I've been doing some basic C++ programming and was wondering if anyone could answer some questions.

Does anyone know of any c++ commands to clear the screen in a basic text application?

I'm also trying to find information on the the uses of time and delays within text applications, such as making the screen wait several seconds before displaying a readout or cout line, etc.

Any links or advice would be much appreciated.

If these questions arent clear enough to illicit a response, please contact me and I'll try to clarify.


If I'm correct, clearing the screen is system-specifc. If you're on windows you can try "System("cls")", but I forgot if it's 's' or 'S'... Just try both. I think its in cstdlib.

You can use the function time() from ctime to get the amount of seconds since 1970.. Then to time that each cout, for example, is displayed at an interval of 500 milliseconds, for example, you do this:

unsigned milli = time(NULL) * 1000;
cout << "Hi!" << endl;
while ((time(NULL) * 1000) - milli < 500)
/*wait*/;
cout << "Hi! .5 seconds after!" << endl;




Good luck!

Share this post


Link to post
Share on other sites
If your using a Win32 Console it is better to use the console functions rather than system("cls"). And Sleep(1000) is rather simple, you have to include windows.h


#include <windows.h>

void clrscr()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 };

DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;

GetConsoleScreenBufferInfo( hConsole, &csbi );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );

GetConsoleScreenBufferInfo( hConsole, &csbi );

FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );

SetConsoleCursorPosition( hConsole, coordScreen );
}

#include <iostream>

int main()
{
std::cout << "hello world";

Sleep(5000);
clrscr();

std::cout << "I said, hello world!\n";
}




[Edited by - simon10k on April 20, 2006 2:33:31 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!