gpt4 book ai didi

c++ - 错误: Invalid conversion from 'int' to 'const char*'

转载 作者:行者123 更新时间:2023-12-02 11:14:21 24 4
gpt4 key购买 nike

编译器给我一个错误:“从'int'到'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;
}

最佳答案

integerstring转换为int。但是您传递的是char,而不是string

关于c++ - 错误: Invalid conversion from 'int' to 'const char*' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23016816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com