2017-08-10 26 views
-2

我正在製作一個程序,用於轉換羅馬數字並將它們轉換爲十進制值。我有一個頭文件一直給我以下錯誤:使用「長度」在頭文件的For循環中出錯C867

錯誤C3867'std :: basic_string,std :: allocator> :: length':非標準語法;使用「&」創建一個指向成員RomanChar

其中「RomanChar是在Visual Studio項目的名稱。出現此錯誤的for循環中,我創建由於」。長度」部分。

我試着尋找到解決問題的對策,往往問題會涉及加括號的成員或使用一種叫做gcroot這是我一直無法理解。

#include <iostream> 
#include <string> 
using namespace std; 

class RomanClass { //Define class "RomanClass" 
public: 


    void setValue(int x) { 
     Value = x; 
    } 

    int getValue() { 
     return Value; 
    } 

    void setValue(string s) { 

     for (int i = int(s.length) - 1; i >= 0; i--) { 

      if (s[i] == 'M' || 'm') { 
       Value += 1000; 
      } 

      else if (s[i] == 'D' || 'd') { 
       Value += 500; 
      } 

      else if (s[i] == 'C' || 'c') { 
       Value += 100; 
      } 

      else if (s[i] == 'L' || 'l') { 
       Value += 50; 
      } 

      else if (s[i] == 'X' || 'x') { 
       Value += 10; 
      } 

      else if (s[i] == 'V' || 'v') { 
       Value += 5; 
      } 

      else if (s[i] == 'I' || 'i') { 
       Value += 1; 

     } 


    } 

} 

private: 

    int Value = 0; 
}; 

回答

1

s.length應b e s.length()。長度是一個成員函數。