Printing in windows console on x,y position

时光怂恿深爱的人放手 提交于 2019-12-11 09:58:23

问题


I want to print, in a certain (X,Y) position, on a standard console in windows.
I tried to use conio.h, but is deprecated/non-existing. There was the gotoxy(x,y) method that seems to be what I want. I've tried these ways, but it just prints extra characters:

    printf("%c[%d;%df",0x1B,y,x);
    printf("\x1B%c[%d;%df",0x1B,y,x);
    printf("\x1B[%d;%dH", 0x1B, y, x);  

Thanks in advance.


回答1:


The Windows API call to position the cursor in a console is SetConsoleCursorPosition.

As someone commented, "curses" is a cross platform console library for doing stuff like this: implementations exist for Windows. ("PDcurses" I think is one such implementation.) These will let you do things like, color, cursor position, etc., and have your program port to other OS, such as Linux.

The printf statements you list are escape sequences for several types of terminals out there. Unfortunately, Windows does not use escape sequences for terminal positioning stuff.



来源:https://stackoverflow.com/questions/8829017/printing-in-windows-console-on-x-y-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!