-1

I know that this question has been asked often, but I can not find an answer that I understand. my program clears out the text, but then the text contues right were it left off.

  • 4
    There is no standard for this. You'll have to use a mechanism specific to your operating system. – Raymond Chen Feb 25 '22 at 01:17
  • C++'s standard IO is really really simple because often C++ is being implemented on systems where concepts like "screen" simply do not exist. The program is often dumping data out onto some wire and whatever happens at the other end of the wire is outside of the control or scope of the program. – user4581301 Feb 25 '22 at 01:35

1 Answers1

0

the easiest way to do this is just to use printf as such:

    printf("\033[%d;%dH", (x), (y));

this should execute the \033 command (which relocates the cursor) in the console with arguments of int x and int y or in your case 0, 0 since you are trying to set the cursor to the top of the screen

Ethan
  • 7
  • 5
  • 2
    You should explain how this works, and in what software environments. – Chris Feb 25 '22 at 01:48
  • @chris as far as I know this should work for any console based enviorment – Ethan Feb 25 '22 at 01:53
  • 3
    Windows consoles before Windows 10 didn't support ANSI escape sequences, so there goes one example where it won't work. https://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line In general, it might be enough to mention that this is not C++ standard, but terminal-specific behaviour and not every terminal supports it. Also, the name "ANSI escape sequence" for further duckduckgoing would be helpful. – Yksisarvinen Feb 25 '22 at 02:17