I am trying to clear the console in C++. I know printing a number of newlines is a bad practice, as it can be slow and is not always reliable to completely clear the console window, but I have researched multiple options and have found almost no other solutions besides system("cls")
, which is an even worse option.
Essentially, I have used the line cout << string(100, '\n');
but I am getting a near-unidentifiable error when I try to run the program.
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)
I have also researched this, and found that most explanations were too complicated for me as a beginning C++ programmer to understand, or completely unrelated to my problem.
My questions are (1) is there a way to fix this error, and (2) could there be a better, cross-platform way of clearing the console other than printing 100 newlines?
I also heard of Console.clear()
, but I'm unsure if this is cross-platform. From what I've seen, it looks more like a Windows command. I've also heard of the curses
library, which I was willing to research and use, until I read somewhere that it was not recommended to use the functions which I am familiar with coupled with the curses library functions.
Thank you in advance!