clrscr() in VC++?

Started by
4 comments, last by Kint 22 years, 4 months ago
Hi! the function clrscr() doesnt work in VC++, but it does work in C++ Builder. What the function does is, it clears the screen of a console application, removing all text. Is there a similiar function in VC++ aswell? Maybe clrscr() actually does exist in VC++ but in that case how do you implement it in a program? What headerfile do you have to include? thanks
Advertisement
On an ANSI console (that is, with ansi.sys loaded up in the system), print out the following string "0x1B[2J".
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
If you don''t want to depend on ansi.sys (most systems don''t load it), you could use
system("cls"); 
.
Kill mages first!
What header do I need to use system()?
The system function passes command to the command interpreter, which executes the string as an operating-system command. system refers to the COMSPEC and PATH environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows NT). If command is NULL, the function simply checks to see whether the command interpreter exists.

Example

/* SYSTEM.C: This program uses
* system to TYPE its source file.
*/

#include "process.h"

void main( void )
{
system( "type system.c" );
}


That should help =)

Axe


Edited by - Axehandler on December 14, 2001 2:30:32 PM
Process.h is not a standard header file. The system function is in stdlib.h. Also, you can clear a Win32 Console using the Win32 console API (I hope I do this correctly ):
    bool ClearScreen(void) {   HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);   CONSOLE_SCREEN_BUFFER_INFO csbi;   if(!GetConsoleScreenBufferInfo (hconsole, &csbi))       return false;   COORD coordScreen = { 0, 0 };   DWORD cCharsWritten;   DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;   return (FillConsoleOutputCharacter (hconsole, ' ', dwConSize, coordScreen, &cCharsWritten) &&           FillConsoleOutputAttribute(hconsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten) &&           SetConsoleCursorPosition(hconsole, coordScreen));}  

[Edited for line length]
[Resist Windows XP's Invasive Production Activation Technology!]

Edited by - Null and Void on December 14, 2001 5:29:47 PM

This topic is closed to new replies.

Advertisement