2014-04-11 80 views
-3

編譯器給我一個錯誤:「從‘詮釋’到‘爲const char *’轉換無效的違規行爲:錯誤:從「詮釋」到「爲const char *」無效轉換

change[j]=oper[integer(A[i][j]+A[i][j+1])][0]; 

哪裏是我的麻煩?

#include <iostream> 
#include <sstream> 
#include <vector> 

using namespace std; 

string mas[10000000],oper[100]; 

int integer(string a) 
{ 
    int numb; 
    istringstream(a)>>numb; 
    return numb; 
} 

int main() 
{ 
    int l,k,i,d=0; 
    string temp1,temp2,s,t,ans="-1",change; 
    vector<string> A,B; 
    for (i=0;i<10000000;++i) 
    mas[i]="-1"; 
    for (i=0;i<100;++i) 
     oper[i]="-1"; 
    cin>>l>>s>>t>>k; 
    for (i=0;i<k;++i) 
    { 
     cin>>temp1>>temp2; 
     oper[integer(temp1)]=temp2; 
    } 
    A.push_back(s); 
    while(A.size()>0) 
    { 
     if (ans!="-1") 
      break; 
     for (i=0;i<A.size();++i) 
     { 
      if (ans!="-1") 
       break; 
      for (int j=0;j<l-1;++j) 
      { 
       change=A[i]; 
       change[j]=oper[integer(A[i][j]+A[i][j+1])][0]; 
       change[j+1]=oper[integer(A[i][j]+A[i][j+1])][1]; 
       if(oper[integer(A[i][j]+A[i][j+1])]!="-1" && mas[integer(change)]!="-1") 
      { 
       if (mas[integer(change)]==t) 
       { 
        ans=d; 
        break; 
       } 
       mas[integer(change)]=d+1; 
       B.push_back(change); 
      } 
     } 
    } 
    A=B; 
    B.clear(); 
    } 
    cout<<ans<<endl;; 
    return 0; 
} 
+1

添加兩個字符給出一個整數。 'integer'接受一個字符串。 – chris

+2

我的天啊,滿滿的括號! –

+0

@ dyp的評論是指原始標題;從那以後它被修改了。 –

回答

0

integer轉換一個stringint,但你傳遞一個char,而不是一個string

0

A是矢量<的std :: string >,所以A [j]爲字符串,所以A [j]的[i]是字符串的字符。

沒有試圖理解目的是什麼,我可以說A [j] [i] + A [j] [i + 1]將字符加起來爲,所以如果兩個字符都是'A'並且作爲「A」是由65表示的,該結果值將是130 - >「E」

然後你把這個字符,並把它在方法,接受字符串,因此炭無效輸入。

相關問題