[英]error: cannot convert const string to const char* for argument 1 to size_t strlen(const char*)
I'm pretty new to C++ and am very confused as to what is happening here. 我对C ++还是很陌生,对于这里发生的事情非常困惑。 The error is the line
int len = strlen(strin);
错误是
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
. strlen
对std::string
一无所知。 It is a C function that returns the length of a null-terminated string. 它是一个C函数,该函数返回以null结尾的字符串的长度。
Fortunately std::string
knows its own length. 幸运的是
std::string
知道自己的长度。 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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.