Question

This is my first post. How do you clear the screen in a console application written in C++? Please understand I don't want to use any extra preprocessors. Would have to do:

cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

Could I do that, is there a more professional way of doing this?

Was it helpful?

Solution

In pure C++ you cannot since C++ doesn't even have the concept of a console. You could essentially be printing to anything(file, printer, dashboard) or even redirecting to another program etc.

It therefore depends on the OS or relies on you using a Library such as ncurses

In windows, for example, you can do the following

#include <stdlib.h>

int main(int argc, char* argv[])
{
  system("cls");
  return 0;
}

OTHER TIPS

too simple depending on your OS.

on linux use >

 system("clear");

on windows use >

system("cls");

for cross platform app you can use both together. It would not harm your program as such.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top