简体   繁体   English

密码程序在C ++中不起作用

[英]password program not working in c++

Password program not working...im working with dev c++ and it dosent recognize conio.h...please help...what shoud i do??maybe i have another errors...please say to correct it.tnx 密码程序不起作用...我正在与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;}
}

Because conio.h is not part of the C standard. 因为conio.h不是C标准的一部分。 It is a Borland extension, and works only with Borland compilers (and perhaps some other commercial compilers). 它是Borland的扩展,仅与Borland编译器(也许还有其他一些商业编译器)一起使用。 Dev-C++ uses GCC, the GNU Compiler Collection, as it's compiler. Dev-C ++使用GCC(GNU编译器集合)作为其编译器。 GCC is originally a UNIX compiler, and aims for portability and standards-compliance. GCC最初是UNIX编译器,旨在实现可移植性和符合标准。

If really can't live without them, you can use Borland functions this way: Include conio.h to your source, and add C:\\Dev-C++\\Lib\\conio.o to "Linker Options" in Project Options (where C:\\Dev-C++ is where you installed Dev-C++). 如果真的不能没有它们,可以通过以下方式使用Borland函数:将conio.h包含到源代码中,并将C:\\ Dev-C ++ \\ Lib \\ conio.o添加到“项目选项”中的“链接器选项”(其中C :\\ Dev-C ++是安装Dev-C ++的位置)。 Please note that conio support is far from perfect. 请注意,conio支持远非完美。

AJ is correct but note that other systems such as Linux, Win32 and OS/2, provide different implementations of these functions. AJ是正确的,但请注意其他系统(例如Linux,Win32和OS / 2)提供了这些功能的不同实现。

On a linux system the #include <curses.h> will give you almost all the functionality that was provided by conio.h 在Linux系统上, #include <curses.h>将为您提供conio.h提供的几乎所有功能。

For getch() and friends, your first stop might be there. 对于getch()和朋友,您的第一站可能在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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