and here is the following code:(I don't know why the window for showing my post doesn't cover all my post)
Number Number::operator+( Number rhsNumber)
{
Number temp;
temp._numbers =ConvertToString(atof(this->_numbers.c_str())+atof(rhsNumber._numbers.c_str()));
return temp;
}
void Number::print()
{
cout<<_numbers<<endl;
}
string ConvertToString(double value)
{
std::stringstream ss;
ss << setprecision(15)<<value;
return ss.str();
}
int _tmain(int argc, _TCHAR* argv[])
{
Number a="1.21111111111111111111111111111111111112222";
Number b="2.1111111";
Number c=a+b;
c.print();
system("PAUSE");
return 0;
}
The thing is: suppose I'm an user. So I can use a Number object with arbitrary length, after computing the result should be saved with the precision that I've gave the Number object (in this situation the length of result should be saved).
But in my program it depends on setprecision(int n). The user has no choice. and it's a pointless.