c++ - Error: Invalid conversion from 'int' to 'const char*' -
the compiler gives me error: "invalid conversion 'int' 'const char*'. offending line is:
change[j]=oper[integer(a[i][j]+a[i][j+1])][0];
where trouble?
#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; (i=0;i<10000000;++i) mas[i]="-1"; (i=0;i<100;++i) oper[i]="-1"; cin>>l>>s>>t>>k; (i=0;i<k;++i) { cin>>temp1>>temp2; oper[integer(temp1)]=temp2; } a.push_back(s); while(a.size()>0) { if (ans!="-1") break; (i=0;i<a.size();++i) { if (ans!="-1") break; (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; }
integer
converts string
int
. passing in char
, not string
.
Comments
Post a Comment