Too many arguments to function call, expected 0, have 1. "InfInt.h" toString function
An answer to this question on Stack Overflow.
Question
I am using c++ to solve a problem. I need to find the factorial of 100 and find the sum of its digits. Because of the limitation of the variables in c++ I am using a header file called infint (https://code.google.com/p/infint/). It has its own function to convert an InfInt to a string. However I am getting this error:"Too many arguments to function call, expected 0, have 1." I am using xcode also.
My code:
#include <iostream>
#include "InfInt.h"
#define INFINT_USE_EXCEPTIONS
using namespace std;
int main() {
InfInt result=1;
for (int x=100;x>0;x--) {
result*=x;
}
cout<<result<<endl;
InfInt I;
string sresult = I.toString(result);
cout<<sresult<<endl;
return 0;
}
I cannot include the full header code but you can download it from the link.
Part of header for toString:
inline std::string InfInt::toString() const
{//PROFILED_SCOPE
std::ostringstream oss;
oss << *this;
return oss.str();
}
There are other references to the method in the header file but I believe this is the only important part.
Answer
Try:
#include <iostream>
#include "InfInt.h"
#define INFINT_USE_EXCEPTIONS
using namespace std;
int main() {
InfInt result=1;
for (int x=100;x>0;x--) {
result*=x;
}
cout<<result<<endl;
string sresult = result.toString();
cout<<sresult<<endl;
return 0;
}
Note that result is an InfInt object and that this object has a method toString() that returns a string representation of it.