Colorizing text in the console with C++(使用 C++ 为控制台中的文本着色)
问题描述
如何使用 C++ 将彩色文本写入控制台?也就是说,如何用不同的颜色写出不同的文字?
How can I write colored text to the console with C++? That is, how can I write different text with different colors?
推荐答案
为您的控制台文本
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;
}
字符属性一>以下是k"值的解释方式.
Character Attributes Here is how the "k" value be interpreted.
这篇关于使用 C++ 为控制台中的文本着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!