我的 C++ 程序有一些错误。我需要创建 2 个排序列表,第 3 个是从前 2 个中排序出来的。
void arrayInp()
/* Create 2 vectors by the length defined by the user*/
{
int a,b,c,d,i,j;
Array A,B; /* HERE i get the error used varaibls, why?*/
int rez[20];
cout<<"enter length of the first array: ";
cin>>a;
cout<<"enter length of the second array: ";
cin>>b;
cout<<"insert first array:";
for (i=0;i<=a;i++)
cin>>c;
A.els[i]=c;
cout<<", ";
cout<<"insert second array:";
for (j=0;j<=a;j++)
cin>>d;
B.els[j]=d;
cout<<", ";
}
我导入的 header 包含:
const int dim = 10;
struct Array
{
int n;
int els[dim];
};
谢谢你的帮助
最佳答案
警告可能来自您未使用的 rez
。
我第一次看代码时,就知道您来自 python。该代码导致未定义的行为(可能取决于索引的内容):
int a,b,c,d,i,j;
Array A,B; /* HERE i get the error used varaibls, why?*/
//...
for (i=0;i<=a;i++)
cin>>c;
A.els[i]=c;
cout<<", ";
看到错误了吗?
for (i=0;i<=a;i++)
{
cin>>c;
}
A.els[i]=c;
cout<<", ";
现在怎么样?
关于c++ - 未使用的变量错误,虽然它不应该,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9720103/