打印在Windows控制台上的X,Y位置 [英] Printing in windows console on x,y position

查看:430
本文介绍了打印在Windows控制台上的X,Y位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打印,在一定的(X,Y)的位置,在窗口的标准控制台上。结果
  我试图用CONIO.H,但德precated /不存在的。有,这似乎是我想要的gotoxy(X,Y)的方法。我已经试过这些方式,但它只是打印多余的字符:

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);  

先谢谢了。

推荐答案

在Windows API调用将光标定位在控制台的 SetConsoleCursorPosition

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

正如有人评论说,诅咒是做的东西像这样的跨平台控制台库:用于Windows存在的实现。 (PDcurses我认为这是一个这样的实现)。这些会让你不喜欢的东西,颜色,光标位置等,让你的程序移植到其他的操作系统,如Linux。

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.

在列表中的的printf 语句是几种类型的终端在那里转义序列。不幸的是,Windows不使用转义序列终端定位的东西。

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.

这篇关于打印在Windows控制台上的X,Y位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆