更改cout文本C ++的颜色 [英] Change color of cout text C++

查看:190
本文介绍了更改cout文本C ++的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图改变一些cout输出的颜色,但后cout再次是相同的颜色。

  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),4); 
cout<< Help-Please<< endl;

但它仍然继续,即使cout已经完成。还要补充说,其中一些颜色更改将在if语句内。

解决方案

文本颜色保持有效,必须调用SetConsoleTextAttribute



编辑:每个文本输出将使用最后一次调用SetConsoleTextAttribute的颜色,因此您可以在不同的行中使用不同的颜色或字/字符)。


Im trying to change the color of some of my cout outputs but after that cout to be again the same color.

Ive tried the following code:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
        cout << "Help-Please" << endl;

but it continues even after the cout has been completed. Also to add that some of these color changes will be inside if statements. What code would you recommend me to add to to get this effect?

解决方案

The text color stays in effect, you must call SetConsoleTextAttribute again with other (the previous) colors.

Edit: Each text output will use the colors of the last call to SetConsoleTextAttribute, so you can use different colors in different lines (or words/characters).

这篇关于更改cout文本C ++的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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