Move text cursor to particular screen coordinate?

后端 未结 7 1843
余生分开走
余生分开走 2020-12-31 19:01

How can I set the cursor at the desired location on the console in C or C++?

I remember a function called gotoxy(x,y), but I think its deprecated. Is th

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 19:53

    This was on stackoverflow...

    `#include 
    
    // ESC-H, ESC-J (I remember using this sequence on VTs)
    #define clear() printf("\033[H\033[J")
    
    //ESC-BRACK-column;row (same here, used on terminals on an early intranet)
    #define gotoxy(x,y) printf("\033[%d;%dH", (y), (x))
    
    int main(void)
    {
        clear();
        gotoxy(23, 12);
        printf("x");
        gotoxy(1, 24);
        return 0;
    }`
    

提交回复
热议问题