clrscr(); equivalent in Code::Blocks

c++, codeblocks

Solution

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.

Problem

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() ; ```

Original source