clrscr(); equivalent in Code::Blocks

gandalf picture gandalf · Jul 22, 2013 · Viewed 88.1k times · Source

how to clear the output console in code blocks?? why doesn't clrscr(); work in Code::Blocks but works in Borland??

I have already tried:

cout << "\x1b[2J\x1b[1;1H" << flush;
cls() ;

Answer

greatwolf picture greatwolf · Jul 22, 2013

The easiest most straightforward way is to just do it through system function call:

#include <stdlib.h>

int main()
{
  system("cls");
}

If you want to do it programmatically MSDN shows how here.

Note that there is no standard function provided by C++ for clearing the console. Some compilers, like borland, provides it as a non-standard function for convenience but it's not portable between different compilers.