Mainly when we are working with console application in C/C++ we come across some scenario where we need clear screen using C++ or C programing language.
There are many different ways available for c++ clear screen.
C++ clear screen in turbo C++ compiler
In Turbo c++ compiler you can use clrscr (); for clear screen.
For c++ clear screen you will require to add conio.h header file.
C++ clear screen in Visual C++ or other IDE
For clear screen in C++ you can use system(“CLS”);
You will require to add standard library header file <stdlib.h>
You can also use system command with clear also example: system(“clear”); It is normally used in POSIX.
Flushing output stream by flush
You can add flush at the end for cout.
cout << “Flushing the output stream.” << flush;
Clear screen in C++ in both Windows and Linux:
cout << "\033[2J\033[1;1H";
This is special string which is similar to clrscr();
c++ clear screen without SYSTEM(“cls”)
cout << string( 100, '\n' );
This is not efficient way but by adding many \n it will automatically clear current screen.
Also in C++ if want to flush we can use cout.flush() function also.
Conclusion:
We have described many different solutions for c++ clear screen. Again it might depend on which IDE and compiler of C++ you are using. It also depend on Operating system you are using for C++ development. some solution might not work for you. You can try all given solution and one of solution will surely work for clearing screen in C++. In case if you are facing any issue you can contact us or comment you problem we will like to help you for same.
Leave a Reply