相关疑难解决方法(0)

如何使用ANSI Escape代码在Console上输出彩色文本

在这里阅读有关ANSI-C转义码的内容.试图在C/C++ printf/cout中使用它来为输出的文本着色,但没有成功.

码:

#include <iostream>

 #include <cstdio>

int main()
{

    int a=3, b=5;
    int &ref = a;

    ref = b;

    //cout << "\155\32\m" << a << b <<'\n'; //here it prints m?m 5, no colored text
    printf("\155\32\m %d",a); //here to it prints same - m?m 5, 

    getchar();

}
Run Code Online (Sandbox Code Playgroud)

如何使用这些转义码将彩色文本输出到控制台?

我错过了什么吗?

编辑:在一些C++代码中,我看到了对此函数的调用

textcolor(10);
Run Code Online (Sandbox Code Playgroud)

但它在g ++和Visual Studio中提供了编译错误.哪个编译器有此功能?任何细节?

c c++ colors

5
推荐指数
4
解决办法
3万
查看次数

标签 统计

c ×1

c++ ×1

colors ×1