【发布时间】:2021-02-26 12:16:23
【问题描述】:
我正在尝试采用十六进制颜色代码并确定它是哪种颜色,我只使用五种基本颜色。这是我获取 rgb 并返回十六进制代码的代码。
string rgbtohex(int r, int g, int b, bool with_head) //the following turns rgb values to hex values.
{
stringstream ss;
if (with_head)
ss<< "#";
ss<<hex<<(r << 16 | g << 8 | b );
return ss.str();
}
我可以用这个输出十六进制代码
cout<<rgbtohex(r,b,g,true)<<endl; //outputs hex color code
我想创建一个函数来获取 rgbtohex 输出并返回颜色。像这样的
string hextocolor()
{
if(rgbtohex(r,g,b,true) = "#ff0000"){
cout<<"Red"<<endl;
}
}
【问题讨论】:
-
问题是什么?
-
和your previous question有什么区别?