2014-10-31 67 views
-1

在這裏,我有一個函數將字符串轉換爲int並存儲到一個數組 ,但它不工作,我得到這個有效期:通過atoi將字符串轉換爲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::allocator<char>>::c_str' to create a pointer to member 

如何解決呢? 幫我請 注:號碼[]類型爲int 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; 
    } 
+2

'd.c_str'應該是' d.c_str()'。 – cdhowie 2014-10-31 19:14:16

回答

1

c_str是一種方法,所以應該用括號被稱爲:

number[g] = atoi(d.c_str()); // Note the brackets