密码程序不起作用...我正在使用 dev c++ ,它可以识别conio.h ...请帮助...我应该怎么做?也许我还有其他错误...请说一下以纠正它。tnx

#include<string.h>
#include<iostream>
#include<stdio.h>
#include<conio.h>

using namespace std;

void main()
{
    char pass[5];
    int o;
    string password= "password";//this is the password
    for(int i=0;i<5 ;i++)
    {
        pass[i]=_getch();
        _putch('*');
    }
    string a(pass);
    if(a==password)
    {cout<<"correct"<<endl;}
    else
    {cout<<"wrong"<<endl;}
}

最佳答案

因为conio.h不是C标准的一部分。它是Borland的扩展,仅与Borland编译器(也许还有其他一些商业编译器)一起使用。 Dev-C++使用GCC(GNU编译器集合)作为其编译器。 GCC最初是UNIX编译器,旨在实现可移植性和符合标准。

如果真的不能没有它们,可以通过以下方式使用Borland函数:
将conio.h添加到您的源代码中,然后将C:\ Dev-C++ \ Lib \ conio.o添加到“项目选项”中的“链接器选项”(其中C:\ Dev-C++是安装Dev-C++的位置)。
请注意,conio支持远非完美。

关于c++ - 密码程序在C++中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19443502/

10-09 13:41