我有一个问题想问这个网站上的每个人。我想让我的数组语句颜色在每一行发生变化。我的意思是,我的数组语句的每一行都有不同的颜色。这是我的程序
#include<conio.h>
#include<windows.h>
#include<iostream>
using namespace std;
int main()
{
system("color 0B");
ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
cout<<"\n Printing array index in char program";
char data[27]={' ','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int x;
for(x=0;x<28;x++)
{
cout<<"\n\n Input array index : ";
cin>>x;
cout<<"Character you are looking for is "<<data[x];
}
getch();
}
我想要 cout<<"\n\n Input array index : ";
中的颜色变化声明和 cout<<"Character you are looking for is "<<data[x];
陈述。请帮助我:)
最佳答案
您可以使用 Windows console functions像SetConsoleTextAttribute
:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
std::cout << "This text should be green" << std::endl;
免责声明:我真的不知道(也无法测试)它是否适用于 C++ 标准输出流,或者是否必须使用 WriteConsole
.
关于c++ - 如何使每个线数组中的颜色发生变化 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33756541/