Clearing only part of the console output

前端 未结 3 1390
生来不讨喜
生来不讨喜 2020-12-29 16:48

What I want to do:

The cursor is initially blinking on the top left corner of the screen:

160 characters remaining
_

3条回答
  •  清歌不尽
    2020-12-29 17:23

    Win32 console doesn't support escape sequences. You can use Console API.

    Tiny example that clears first 3 characters at (0, 0) from your console

    #include 
    
    int main()
    {
       HANDLE hOutput = ::GetStdHandle(STD_OUTPUT_HANDLE);
    
       COORD coord = {0,0};
       ::SetConsoleCursorPosition(hOutput, coord);
    
       char buff[] = "   ";
       ::WriteConsoleA(hOutput, buff, 3, NULL, NULL);
    
       return 0;
    }
    

    If you don't like Console API and wish to use ncurses analog, see there.

提交回复
热议问题