+ 5
Can you clear terminal in c++
I want to draw to the terminal and then clear it
9 Antworten
+ 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..
+ 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
+ 2
A thread about conio.h
https://www.sololearn.com/Discuss/1947816/?ref=app
Edit: A discussion thread about turbo c++ that some might find helpful
https://www.quora.com/What-is-the-difference-between-using-Turbo-C-and-GNU-C-C++-Is-there-any-real-difference-or-if-I-submit-the-C-file-would-that-be-the-same-thing?top_ans=17291089
+ 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.
0
Thanks
0
It says I can't include conio.h
0
No
0
Just sololearn. My computer is currently downloading vocode for cpp
- 4
#include <conio.h>
now use clrscr() to clear the console