console problem

Started by
15 comments, last by ATronic 22 years, 3 months ago
Hey, I have tried to find this many places and failed. I want to clear the contents of my console app''s window. Such as in dos when you type CLS. I tried the known command
  system("cls");  
But it had no effect. Is there another way? It needs to be fairly fast so I can get a decent looking refresh rate for my ASCII based rpg. Thanks a ton to all who answer. Right now I''m stuck doing something equivilant to
  cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n...  
Thanks again. Alex Broadwin A-Tronic Software & Design ----- "if you fail in life, you were destined to fail. If you suceed in life, call me." "The answer is out there." "Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Advertisement
There are better ways, but this should do it ...
        DWORD numCharactersWritten;COORD consoleCoords = {0, 0};GetConsoleScreenBufferInfo(consoleHandle, &consoleInfo);FillConsoleOutputCharacter(consoleHandle, ' ', consoleInfo.dwSize.X * consoleInfo.dwSize.Y,    consoleCoords, &numCharactersWritten);FillConsoleOutputAttribute(consoleHandle, consoleInfo.wAttributes,    consoleInfo.dwSize.X * consoleInfo.dwSize.Y, consoleCoords, &numCharactersWritten);        

... where consoleInfo is a CONSOLE_SCREEN_BUFFER_INFO, and consoleHandle is a HANDLE to a console.

Edited by - Martee on January 8, 2002 10:57:45 PM
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
I don''t think this will work in my situation. This is the base of the console app, the skeleton code you begin with.

  #include <iostream>using namespace std;int main( void ){	cout << "This is a test" ;	return 0;}  


I have no win32 at all, nothing using windows.h! So how would I clear this screen. I have only basic knowledge on console apps, as you probably can see.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
If you include windows.h, it should work. I used the above code in a similar program. But otherwise ... I don''t know of any non-Windows ways of doing it.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
You could just do a system call.

system("cls";


?
I tried including windows.h, no luck. Thanks anyway. I decided to make it using win32 and win32 draw functions. I''m building my own basic cout with \n and so on. More flexible anyway I guess. Easy to port too. Thanks for your time.


Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
It''s a little ugly, but you should be using a console buffer anyway... this might help you on your way...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/conchar_25b9.asp

D
is it win32 or dos based.

If it is not a win32 exe (if your lucky you can still pull it off) jsut #include <conio.h> and use clrscr();

there are equivilent functions and workarounds in stdio, but I forgot what they were as I always used conio.
Beer - the love catalystgood ol' homepage
win32 exe I believe. As usual, an emulated console.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
did you included cstdlib?
If you did what happened with system ("cls");
humanity will always be slaved by its ignorance

This topic is closed to new replies.

Advertisement