我正在编写一个代码,我需要根据用户提供的输入以不同的颜色显示输出。 我怎样才能做到这一点? 尝试使用以下代码,但它无效。
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
system ( "TITLE Color Check" );
for(int i=0;i<10;i++)
{
system ( "COLOR i" );
cout << "This color is COLOR" << i << endl;
}
system("PAUSE");
return 0;
}
答案 0 :(得分:1)
这应该有效:
for(int i = 31; i < 38; i++)
cout << "\e[0;" << i << "m"<< "This color is COLOR " << i << "\e[0;0m" << endl;
只需使用正确的颜色代码: