简体   繁体   中英

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

#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. It is a Borland extension, and works only with Borland compilers (and perhaps some other commercial compilers). Dev-C++ uses GCC, the GNU Compiler Collection, as it's compiler. GCC is originally a UNIX compiler, and aims for portability and standards-compliance.

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++). Please note that conio support is far from perfect.

AJ is correct but note that other systems such as Linux, Win32 and OS/2, provide different implementations of these functions.

On a linux system the #include <curses.h> will give you almost all the functionality that was provided by conio.h

For getch() and friends, your first stop might be there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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