我是 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/