繁体   English   中英

我是 C++ 的新手,我得到了这个错误帮助。 我很确定这是一个简单的解决方法,但我查找的答案没有意义

[英]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的指针 另一方面,变量rint 所以当你写:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM