Archived

This topic is now archived and is closed to further replies.

Kint

clrscr() in VC++?

Recommended Posts

Kint    122
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

Share this post


Link to post
Share on other sites
Fruny    1658
On an ANSI console (that is, with ansi.sys loaded up in the system), print out the following string "0x1B[2J".

Share this post


Link to post
Share on other sites
Axehandler    122
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

Share this post


Link to post
Share on other sites
Null and Void    1088
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

Share this post


Link to post
Share on other sites