//这个参考一下吧,我运行没问题
#include <iostream>
#include <string>
#include <conio.h> //getch()
using namespace std;
int run() {
//这里放原来的main函数
//cout<<"OK"<<endl;
return 0;
}
string getPW(char pwCh='*'/*密码代替符,可以自定义*/) { //返回加密的密码(password),需要 include <conio.h>
const int pwLen=17; //最大密码长度=16
char pw[pwLen]={0};
for(int i=0;i<pwLen-1;i++) {
pw[i]=getch();
if(pw[i]=='\r') {
pw[i]=0;
cout<<endl;
return string(pw);
}
//else
cout<<pwCh;
}
cout<<endl;
return string(pw);
}
int main()
{
string pw("iloveu"); //password
int counter=3; //密码验证最大次数
//cout<<"Enter password : ";
do {
if(!pw.compare(getPW())) //密码正确
return run();
//cout<<"Wrong password! Enter again : ";
counter--;
}
while(counter);
//cout<<"Error Message";do something else...
return 0;
}