[英]Unused variable error, altought it shouldent
我的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<<", ";
}
我導入的標頭包含:
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<<", ";
現在怎么樣?
如果您是初學者,請嘗試讓Clang編譯您的代碼。 它特別強調可消化的錯誤消息。
如果您不能使用它,那么您仍然可以使用在線版本 ,盡管它在依賴性方面顯然受到限制。
/tmp/webcompile/_1981_1.cc:18:5: warning: unused variable 'rez' [-Wunused-variable]
int rez[20];
^
1 warning generated.
通常,您可以看到用於診斷的信息:
對於此特定警告:實際顯示未使用的變量的名稱。
幫個忙,得到一個友好的編譯器;)
rez
是未使用的變量,不是A
或B
而且您還有其他幾個錯誤。 大括號為一件事。 並且您要求的輸入參數超出了用戶准備提供的輸入參數(在(i=0;i<=a;i++)
)。 然后在第二個塊中使用a
代替上邊界b
。 復制和粘貼錯誤?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.