Reputation: 200
Is their a way to clear the screen in c++ on a mac without using the system("clear"); command? If not is their a way to replace a character?
Upvotes: 2
Views: 1498
Reputation: 168876
If you absolutely do not care about portability, just emit the same sequence of characters that clear
does.
$ clear | od -c
0000000 033 [ H 033 [ 2 J
0000007
$ : "Oh, it is ESCAPE [ H ESCAPE [ 2 J on my computer"
$ cat clear_fun.cc
#include <iostream>
void clear() { std::cout << "\033[H\033[2J" << std::flush; }
$
Upvotes: 6
Reputation: 154035
Standard C++ doesn't talk about a "screen" or something. On UNIXes you can use ncurses. Generally, this just use terminal control codes. Mostly, you can assume that VT100 is the terminal and you can just use the various control codes. How to do it on Windows terminals I don't know.
Upvotes: 1