【发布时间】:2020-10-17 23:06:52
【问题描述】:
我想将文本及其颜色存储在变量中,然后我可以cout。
我试过用这样的字符串来做,但它不起作用。
我想在不同的单词上有不同的颜色并将其存储在一个变量中。
string e = "text\ntext" + SetConsoleTextAttribute(hConsole,64) +
"\ntext" + SetConsoleTextAttribute(hConsole,32);
cout<<e;
[Error] invalid operands of types 'const char*' and 'const char [6]' to binary
'operator+'
【问题讨论】:
-
显式转换
SetConsoleTextAttribute():std::string(SetConsoleTextAttribute(hConsole,64)) -
std::cout不知道如何更改颜色;它只知道如何写字符。您不能将任何内容放入字符串中,这会导致std::cout改变颜色。