使用 C++ 为控制台中的文本着色 [英] Colorizing text in the console with C++

查看:43
本文介绍了使用 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++ 为控制台中的文本着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆