I'm pretty new to C++ and am very confused as to what is happening here. The error is the line int len = strlen(strin);
. Any suggestions how to fix this would be much appreciated.
BigNum::BigNum(const std::string& strin)
{
digits = NULL;
int len = strlen(strin);
if (len == 0)
{
BigNum zero;
*this = zero;
return;
}
used = len;
positive = true;
int i = 0;
if(strin[i] == '-')
{
positive = false;
i = 1;
used--;
}
else if(strin[i] == '+')
{
i = 1;
used--;
}
capacity = double_up_default(used);
digits = new unsigned int[capacity];
for(unsigned int k = 0; k < used; ++k)
{
digits[used - k - 1] = strin[i++] - '0';
}
trim();
}
strlen
knows nothing about std::string
. It is a C function that returns the length of a null-terminated string.
Fortunately std::string
knows its own length. Try this instead:
int len = strin.size();
or, if you care about the range of sizes a string may have,
std::string::size_type len = strin.size();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With