这是我无法正常工作的超载部分。
HexColour HexColour::operator+(const HexColour& other) const
{
HexColour temp;
stringstream r,g,b;
stringstream ro, go, bo;
int x, y, z;
int xo, yo, zo;
r << hex << colour[2] << colour[3];
g << hex << colour[4] << colour[5];
b << hex << colour[6] << colour[7];
r >> x;
g >> y;
b >> z;
ro << hex << other.colour[2] << other.colour[3];
go << hex << other.colour[4] << other.colour[5];
bo << hex << other.colour[6] << other.colour[7];
ro >> xo;
go >> yo;
bo >> zo;
if((x + xo) > 255)
x = 255;
else
x = x + xo;
if((y + yo) > 255)
y = 255;
else
y += yo;
if((z + zo) > 255)
z = 255;
else
z += xo;
cout << x << " anwer" << endl;
cout << y << " anwer" << endl;
cout << z << " anwer" << endl;
直到这里一切正常,xyz 的答案都是正确的;这是问题部分:
r << hex << x; // PROBLEM
g << hex << y; // PROBLEM
b << hex << z; // PROBLEM
r的值为0,为什么?
cout << hex <<r << endl;
temp.colour = "0x" + r.str() + g.str() + b.str();
return temp;
}
我在上面打印的部分是正确的整数值,但 r 不是新的十六进制值??