使用C ++在控制台中着色文本 [英] 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;
}
这篇关于使用C ++在控制台中着色文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文