Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clrscr(); equivalent in Code::Blocks

Tags:

c++

codeblocks

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() ;
like image 457
Cid Avatar asked Jul 22 '13 16:07

Cid


2 Answers

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.

like image 110
greatwolf Avatar answered Sep 28 '22 04:09

greatwolf


You can use the OS commands to clear the contents of the console.

#include<stdlib.h>
int main(){

system("cls");   //For windows
system("clear"); //For Linux

}
like image 40
Sidharth J Avatar answered Sep 28 '22 03:09

Sidharth J