无法输出对象的 red/green/blue 颜色值
Cannot output red/green/blue color value of object
vector<Text> Game_Text;
Game_Text.push_back(Text("0",Game_Font[0],50));
cout<<Game_Text[0].getFillColor().r<<endl;
在 Code::Blocks
中使用 C++11
运行时没有输出,难道不应该输出255吗?如果 Game_Text[0].getFillColor().r
替换为 "test"
,它会正常输出 test
。没有错误,完整代码正在运行。
是否可以使用此方法只输出对象的单个 r/g/b 值?
Color
member r
属于 Uint8
类型,它是 unsigned char
.
的别名
和char
(以及signed char
和unsigned char
,以及基于这些类型的所有别名)被处理为字符输出运算符 <<
.
因此
cout<<Game_Text[0].getFillColor().r<<endl;
将尝试将 r
打印为 字符 。如果它的值不对应于可打印字符,则似乎什么都不会打印。
要打印整数值,您需要将其转换为不基于 char
:
的整数类型
cout << static_cast<unsigned>(Game_Text[0].getFillColor().r) << '\n';
vector<Text> Game_Text;
Game_Text.push_back(Text("0",Game_Font[0],50));
cout<<Game_Text[0].getFillColor().r<<endl;
在 Code::Blocks
中使用 C++11运行时没有输出,难道不应该输出255吗?如果 Game_Text[0].getFillColor().r
替换为 "test"
,它会正常输出 test
。没有错误,完整代码正在运行。
是否可以使用此方法只输出对象的单个 r/g/b 值?
Color
member r
属于 Uint8
类型,它是 unsigned char
.
和char
(以及signed char
和unsigned char
,以及基于这些类型的所有别名)被处理为字符输出运算符 <<
.
因此
cout<<Game_Text[0].getFillColor().r<<endl;
将尝试将 r
打印为 字符 。如果它的值不对应于可打印字符,则似乎什么都不会打印。
要打印整数值,您需要将其转换为不基于 char
:
cout << static_cast<unsigned>(Game_Text[0].getFillColor().r) << '\n';