C++ 通过atoi将字符串转换为int?
这里我有一个函数将字符串转换为int并存储到数组中 但它不起作用,我得到了这个期限:C++ 通过atoi将字符串转换为int?,c++,string,C++,String,这里我有一个函数将字符串转换为int并存储到数组中 但它不起作用,我得到了这个期限: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': function call missing argument list; use '&std::basic_string<char,std::char_traits<char>,std::allo
'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': function call missing argument list; use '&std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str' to create a pointer to member
“std::basic_string::c_str”:函数调用缺少参数列表;使用“&std::basic_string::c_str”创建指向成员的指针
我怎样才能修好它??
请帮帮我
注:数字[]为整数
eq是字符串
void calcu(string s)
{
int size = s.size();
string d = "", st="";
int y = 1;
int g = 0;
for (int i = 0; i < size; i++)
{
if (s[i] == '-')
{
if (i == 0)
y = -1;
else
if (isdigit(s[i - 1]))
y = 1;
else
if (s[i - 1] == '(')
y = -1;
else
if (ispunct(s[i - 1]))
y = -1;
else
st += s[i];## Heading ##
}
else
if (isdigit(s[i]))
d += s[i];
else
{
if (d != "")
{
number[g] = atoi(d.c_str);
number[g] *= y;
y = 1;
arr[g] = char(65 + g);
st += arr[g];
st += s[i];
g++;
d = "";
}
st += s[i];
}
}
eq = st;
}
void计算(字符串s)
{
int size=s.size();
字符串d=“”,st=“”;
int y=1;
int g=0;
对于(int i=0;i
c_str
是一种方法,因此应使用括号调用它:
number[g] = atoi(d.c_str()); // Note the brackets
d.c_str
应该是d.c_str()
。