我用彩色输出编写了这个非常基本的代码行:
printf("\033[1;32m"); // boldgreen code: \033[1;32m according to:
http://web.theurbanpenguin.com/adding-color-to-your-output-from-c/
puts("Enter username:");
gets(user);
在我的计算机中,所有东西都工作正常,并且我得到了预期的彩色输出:
但在其他计算机上我得到这个输出:
\033[1;32mEnter username:
我不得不说我所有的 #include 都很好,我只是复制粘贴到另一台计算机上,如果这很重要的话,我在两台计算机上都使用 Visual Studio。
似乎是基本的事情,但我不明白为什么会发生这种情况。 感谢各位的帮助。
最佳答案
大多数终端都支持颜色。问题在于发送正确的转义码。对于 Windows 命令行,您必须执行不同的转义序列。 There is a wikipedia entry that describes how to do an escape in different environments .
关于C 中的彩色输出到屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53802253/