gpt4 book ai didi

c++ - 使用 C++ 在控制台中为文本着色

转载 作者:IT老高 更新时间:2023-10-28 12:12:20 27 4
gpt4 key购买 nike

如何使用 C++ 将彩色文本写入控制台?也就是不同颜色的文字怎么写?

最佳答案

Add a little Color to your Console Text

  HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// you can loop k higher to see more color choices
for(int k = 1; k < 255; k++)
{
// pick the colorattribute k you want
SetConsoleTextAttribute(hConsole, k);
cout << k << " I want to be nice today!" << endl;
}

alt text

Character Attributes以下是“k”值的解释方式。

关于c++ - 使用 C++ 在控制台中为文本着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4053837/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com