How do I clear the console in BOTH Windows and Linux using C++

There is no generic command to clear the console on both platforms.

#include <cstdlib>

void clear_screen()
{
#ifdef WINDOWS
    std::system("cls");
#else
    // Assume POSIX
    std::system ("clear");
#endif
}

Leave a Comment