c++ - 错误] ISO C++ 禁止指针和整数之间的比较 [-fpermissive]

标签 c++ c pointers integer

我是 C++ 编程的初学者,我在学校有这个事件。我在第 15 行不断收到 [错误] ISO C++ 禁止指针与整数之间的比较 [-fpermissive]。您如何解决这个问题?谢谢!

#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
int pass[5];
int x;
main()
{
    cout<<"\nEnter pin code: ";
    for(x=0;x<=4;x++)
    {
        pass[x]=getch();
        putch('#');
    }   
    if(pass==86222)
        cout<<"\nW E L C O M E!";
    else
        cout<<"\nIncorrect Pin Code";
    getch();
}

最佳答案

你做事的方式很奇怪。如果你想比较int。取int,读取并比较,为什么需要array

最好、最简单的方法是仅使用 int

#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
main()
{
    int pass;
    cout<<"\nEnter pin code: ";
    cin>>pass;

    if(pass==86222)
        cout<<"\nW E L C O M E!";
    else
        cout<<"\nIncorrect Pin Code";
    getch();
}
<小时/>

如果您想按照自己想要的方式进行操作,请使用strcmp()

#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
char pass[5];
int x;
main()
{
    cout<<"\nEnter pin code: ";
    for(x=0;x<=4;x++)
    {
        pass[x]=getch();
        putch('#');
    }   
    if(!strcmp(pass, "86222"))
        cout<<"\nW E L C O M E!";
    else
        cout<<"\nIncorrect Pin Code";
    getch();
}

关于c++ - 错误] ISO C++ 禁止指针和整数之间的比较 [-fpermissive],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33782861/

相关文章:

c++ - Boost interprocess_condition 多个线程调用 wait() 失败

在C中将二维数组的一部分复制到另一个二维数组中

c++ - 指针可以带参数吗?这3种指针有什么区别

c++ - 指针参数和引用参数的区别?

c++ - 为什么外部链接变量可用作常量表达式?

c++ - C++模板中的多步推理器

c - void * 到底是什么意思

c - 警告 : passing argument 1 of ‘word_search’ from incompatible pointer type [enabled by default]

c++ - 创建类型拷贝

c++ - 如何在C程序中直接改变显存映射来绘制像素(无需库函数)