Home c++ Cleaning up the console

Cleaning up the console

Author

Date

Category

How to clear the console screen without connecting libraries ???


Answer 1, authority 100%

# include & lt; stdlib.h & gt;
int main (int argc, char * argv [])
{
 system ("cls");
 return 0;
}

For win:

void clear () {
  COORD topLeft = {0, 0};
  HANDLE console = GetStdHandle (STD_OUTPUT_HANDLE);
  CONSOLE_SCREEN_BUFFER_INFO screen;
  DWORD written;
  GetConsoleScreenBufferInfo (console, & amp; screen);
  FillConsoleOutputCharacterA (
    console, '', screen.dwSize.X * screen.dwSize.Y, topLeft, & amp; written
  );
  FillConsoleOutputAttribute (
    console, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE,
    screen.dwSize.X * screen.dwSize.Y, topLeft, & amp; written
  );
  SetConsoleCursorPosition (console, topLeft);
}

For * nix:

void clear () {
  std :: cout & lt; & lt; "\ x1B [2J \ x1B [H";
}

See here for other known options for clearing the console screen.

asm option for the gifted:

PUSHA;
XOR EAX, EAX;
XOR EBX, EBX;
XOR ECX, ECX;
XOR EDX, EDX;
MOV AH, 6;
MOV DX, 174fh;
INT 10h;
POPA;

This option will not work in Protected Mode.


Answer 2, authority 75%

Like this

cout & lt; & lt; "\ 033 [2J \ 033 [1; 1H";

There are two commands here – clear the screen \ 033 [2J

And move the cursor to the upper left corner \ 033 [1; 1H

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions