错误:从'int'到'const char*'的转换无效
Error: Invalid conversion from 'int' to 'const char*'
编译器给我一个错误:"从‘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;
}
integer
将string
转换为int
。但您传递的是char
,而不是string
。
A是向量<std::字符串>,所以A[j]是字符串,所以A[j][i]是字符串的字符。
在不试图理解目的的情况下,我可以说A[j][I]+A[j][I+1]对字符值求和,因此如果两个字符都是"A",并且"A"由65表示,则结果值将为130->'é'
然后获取这个char并将其放入方法中,该方法接受字符串,因此该char不是有效的输入。
相关文章:
- C++ PTHREADS - 无效转换无效*(*)()到无效*(*)(无效*)
- is_same和variadic模板编译时错误无效转换
- 如何将常量无效*转换为istream?
- 无效* 转换获得意外输出
- 无法确定为什么函数调用中从 char* 到 char 的无效转换
- 在这个简单函数中从'char'到'const char*'的无效转换
- C++从 'const char*' 到 'char*' Arduino Uno 的无效转换
- 如何修复C++中的"错误:从'int'到'const char*'[-fallowive]的无效转换?
- C 错误:从(基类模板)到子类的无效转换
- 如何将常量无效*转换为无符号字符*
- 函数模板中的无效转换错误,返回值取决于其泛型类型
- 常量正确性编译错误到模板函数中的无效转换错误
- 从"char"到"const char*"的无效转换[-fpermissive](idk why)
- 从“ void*”到“ pthread_t*”的无效转换
- 当函数调用时,试图阻止数组更改时发生无效转换错误
- 使用基类中定义的函数返回指向派生类实例的指针时发生无效转换错误
- C++从字符到常量字符*的无效转换
- ALL_OF从'char'到'const char*'的无效转换 [-允许]
- C和C++上的无效转换错误
- C++ 在模板专用化中从 strcmp() 中的 'char' 到 'const char*' 的无效转换