[英]I'm new to C++ and I got this error help. I'm pretty sure its an easy fix but the answers i looked up didn't make sense
我收到此錯誤 [錯誤] ISO C++ 禁止指針和 integer [-fpermissive] #include <stdio.h> 之間的比較
int main()
{
int i[1];
int r = 4;
{
printf("enter a number between 1-10\n");
while (i != r);
{
scanf("%d,&i[0]");
}
printf("good job\n :)");
}
}
問題是上面代碼中的變量i
是一個int
數組,由於類型衰減而衰減為指向int
的指針。 另一方面,變量r
是int
。 所以當你寫:
while (i != r)
這意味着您正在嘗試將指向int
int
比較,因此出現上述錯誤。
要解決此問題,您可以使用以下程序:
#include <iostream>
int main()
{
int arr[4] = {}; //create an array named arr of size 4 with elements of type int all initialized to 0
//iterate through the array and take input from user
for(int &element : arr)
{
std::cout << "Enter number:" << std::endl;
std::cin >> element;
}
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.