How can I clear console using C++?


We can clear the console using C++ code. To do this we have to execute some system commands. In Linux systems, the POSIX is used. We can call system() function to execute system command. For clearing the console in linux, we can use “clear” command. This will be passed inside the system() function.

Let us see the code to get the better idea.

Example

#include <iostream>
using namespace std;
int main () {
   cout << "Now the screen will be cleared!" << endl;
   system("clear");
   cout << "Empty Screen" << endl;
   return 0;
}

Output

After

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements