문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top