+ 5

Can you clear terminal in c++

I want to draw to the terminal and then clear it

26th Aug 2021, 3:28 PM
Bob
Bob - avatar
13 odpowiedzi
+ 9
// use this snippet it must work on all major platforms #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(_WIN64) void clear(){ system("cls"); } #else void clear(){ system("clear"); } #endif // now to use it just call clear() like this int main(){ cout<<"hello "; // assuming you have included libs clear(); cout << "world"; } // a side note : because Sololearn doesn't use real terminal .. dont expect it to clear the screen... no you cant clear the screen of sololearn in anyway ( untill you use some kinda buffer to temporarily store the state and flush when you are done) the real reason is provided by Martin Taylor sir.. for c/c++ it dont even know what a terminal is.. its none of its business..
26th Aug 2021, 6:36 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 4
You can use ansii escape codes . For clearing screen it will be \x1B[2J. So cout << "\x1B[2J" More on them, https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
26th Aug 2021, 4:23 PM
Abhay
Abhay - avatar
+ 2
Harshit Jawla conio.h is from an ancient complier which was never or has been the part of C++ standard libraries, so stop recommending Turbo C headers and it's functions to others here.
26th Aug 2021, 4:43 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
0
Thanks
26th Aug 2021, 3:52 PM
Bob
Bob - avatar
0
It says I can't include conio.h
26th Aug 2021, 3:56 PM
Bob
Bob - avatar
0
No
26th Aug 2021, 4:19 PM
Bob
Bob - avatar
0
Just sololearn. My computer is currently downloading vocode for cpp
26th Aug 2021, 4:22 PM
Bob
Bob - avatar
- 4
#include <conio.h> now use clrscr() to clear the console
26th Aug 2021, 3:49 PM
Harshit Jawla
Harshit Jawla - avatar