How to go up a line in Console Programs (C++)

前端 未结 3 1251
我寻月下人不归
我寻月下人不归 2020-12-17 03:24

In C++ I\'m trying to go back up a line to add some characters. Here is my code so far:

cout << \"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\xc9\\xbb\\n\\xc8\\xbc         


        
相关标签:
3条回答
  • 2020-12-17 03:49

    In windows you can use this example

    there you will create CreateConsoleScreenBuffer() and then are using SetConsoleCursorPosition(console_handle, dwPosition);

    0 讨论(0)
  • 2020-12-17 03:51

    cout will first write to internal buffer and only output it to the screen periodically and not for every character that gets inserted. This is for performance reasons.

    flush tells it to empty the buffer now and show it on screen.

    You should consider a library like ncurses.

    0 讨论(0)
  • 2020-12-17 04:02

    If your console supports VT100 escape sequences (most do), then you can use ESC [ A, like this:

    cout << "\x1b[A";
    

    to move the cursor up one line. Repeat as necessary.

    0 讨论(0)
提交回复
热议问题