在控制台上移动光标 [英] Cursor up on Console
问题描述
您是否知道在控制台应用程序(命令提示符窗口)上通过程序将光标移动一行的简单方法?
在过去,为此目的有ANSI Escape序列,但似乎没有被识别。
光标向上/光标向下的ASCII代码也不起作用。< br $>
我尝试过Curses库,但找不到访问现有应用程序控制台的方法。而且,坦率地说,我更喜欢更简单的东西。
光标回家和屏幕也很受欢迎,但我可以不用它们。
Do you know of a simple way to move the cursor one line up by program on a console application (Command Prompt window) ?
In the old days, there were ANSI Escape sequences for this purpose, but they don't seem to be recognized.
The ASCII codes for Cursor up/Cursor down do not work either.
I have tried the Curses library, but couldn't find a way to access the already existing application console. And, frankly speaking, I'd prefer something simpler.
Cursor home and clear screen are also welcome, but I can do without them.
推荐答案
您可以使用 SetConsoleCursorPosition() [ ^ ]。示例代码可以在使用高级输入中找到和输出函数 [ ^ ]。
You may use SetConsoleCursorPosition()[^]. Example code can be found at Using the High-Level Input and Output Functions[^].
尝试使用ESC [A,像这样:
cout<< \ x1b [A;
将光标向上移动一行。
Try to use ESC [ A, like this:
cout << "\x1b[A";
to move the cursor up one line.
这篇关于在控制台上移动光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!