我尝试在控制台中移动光标。
我发现vt100代码可以做到这一点。
#include<stdio.h>
int main()
{
printf("123456789\n");
printf("\033A");
printf("abcdefghi\n");
return 0;
}它的产量与计划的不一样。这是上面的代码在控制台中打印的内容。
在第二行,"A“前面有一个小箭头,它不能放在网上
123456789
Aabcdefghi在Windows的Visual Studio中编程时如何使用vt100代码?
发布于 2018-07-02 00:34:18
并非所有的平台都支持VT100。仅适用于Windows10及以上版本(你可能注意到PowerShell是有颜色的)。
如果你在Windows10上运行上面的代码,它不能工作;这意味着你还没有激活它(默认情况下它不会打开)。
有一个跨平台的方法(在这种方法中,你不需要使用Windows特定的函数来启动它)。
你只需要在你的控制代码之前调用system(" "):
#include<stdio.h>
#include <stdlib.h> // Library for system() function
int main()
{
system(" "); // Start VT100 support
printf("123456789\n");
printf("\033A"); // And you are away :)
printf("abcdefghi\n");
return 0;
}或者,您可以使用SetConsoleTextAttribute()激活VT100,如here所述
您可以找到控制台虚拟终端序列from the Microsoft Documentation的更多参考资料
以下序列的行为基于VT100和派生的终端仿真器技术,最具体地说是xterm终端仿真器。有关末端序列的更多信息可以在http://vt100.net和http://invisible-island.net/xterm/ctlseqs/ctlseqs.html上找到。
This post also seems helpful as it describes different ways to start VT100
发布于 2013-04-18 19:28:44
VT100代码在正常的Windows控制台中不起作用。你需要一个terminal emulation program。
This page似乎声称它确实支持vt100。但我个人不能证实这一点。我找不到任何推荐人。
可能有些过火了,但是Cygwin包含一个X服务器,您可以使用它来运行支持vt100代码的Xterm。
https://stackoverflow.com/questions/16081639
复制相似问题