【问题标题】:How do I change the colour of output in C [duplicate]如何在 C 中更改输出的颜色 [重复]
【发布时间】:2013-12-08 21:36:24
【问题描述】:

仅供参考,我在 Xcode 中使用的是 C 而不是 C++ 我不能使用 conio.h 我想打印不同颜色的文本。 任何帮助是极大的赞赏 其他帖子中提供的方法不起作用,这就是为什么我再次发布它 谢谢

【问题讨论】:

  • 这个问题已经回答了here

标签: c


【解决方案1】:

使用转义码可以做到这一点

#include <stdio.h>

#define COLOR_RESET  "\x1b[0m"
#define COLOR_RED    "\x1b[31m"
#define COLOR_GREEN  "\x1b[32m"

int main()
{
    printf(COLOR_GREEN "Some good text\n");
    printf(COLOR_RED   "Some evil text\n");
    printf(COLOR_RESET "Some normal text\n");

    return 0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-10
    • 2020-06-18
    • 2013-10-24
    • 2011-08-22
    • 1970-01-01
    相关资源
    最近更新 更多