问题
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