代码之家  ›  专栏  ›  技术社区  ›  One Two Three

转到C++中的控制台位置(在OSX上)

  •  3
  • One Two Three  · 技术社区  · 8 年前

    我有一段c++代码,它在Windows上运行得很好,但我正在尝试将其移植到OSX,并且出现了很多编译错误。

    OSX是否有等效的库?

    #include <windows.h>
    void gotoXY(int x, int y)
    {
         //Set the coordinates
         COORD coord = {x, y};
         //Set the position
         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
         return;
    }
    
    1 回复  |  直到 8 年前
        1
  •  6
  •   iBug    8 年前

    使用nCurses库(推荐),或使用ANSI转义序列:

    // nCurses, you need to initialize the window before
    move(x, y);
    
    // ANSI escape seq
    printf("\033[%d;%dm", x, y);