C++ Stringstream values aren't correct? The result is 0?
This is the overloading part that I cannot get to work properly.
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;
Up until here everything works perfect the x y z answers are correct; this
is the problem part:
r << hex << x; // PROBLEM
g << hex << y; // PROBLEM
b << hex << z; // PROBLEM
The value of r is 0, why?
cout << hex <<r << endl;
temp.colour = "0x" + r.str() + g.str() + b.str();
return temp;
}
The part I print out above this is the correct integer value but r is not
the new Hex value??
No comments:
Post a Comment