c++ - 如何使每个线数组中的颜色发生变化 C++

标签 c++ arrays winapi

我有一个问题想问这个网站上的每个人。我想让我的数组语句颜色在每一行发生变化。我的意思是,我的数组语句的每一行都有不同的颜色。这是我的程序

#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 functionsSetConsoleTextAttribute :

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/

相关文章:

python - 将 OpenGL 模型导出为 .OBJ

arrays - 对 native 数组和对象使用react

javascript - Chart.js 中分组条形图每组不同级别

c++ - Windows C++ 重定向库

c++ - 如何计算 Windows 上的可用地址空间?

c++ - Win32 API : how to make Edit Text to accept unsigned float only in c++?

c++ - 关于使用声明 C++ 的规则

c++ - 我在使用 glDrawRangeElements 时遇到的问题

c++ - 神秘的相对路径库依赖

arrays - 如何将矩阵的单层旋转 n 位?