C++的关于密码
怎样实现输入密码时显示出“*****”以防止密码外泄??会的帮帮忙啊~~~~无限感激~~~~~
http://bbs.bc-cn.net/viewthread.php?tid=102975&star=at
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
char password[100];
int index=0;
while(1)
{
char ch;
ch=getch();
if(ch==8) //退格键
{
if(index!=0)
{
cout<<char(8)<<" "<<char(8);
index--;
}
}
else if(ch=='\r') //回车键
{
password[index]='\0';
cout<<endl;
break;
}
else
{
cout<<"*";
password[index++]=ch;
}
}
cout<<"password:"<<password<<endl;
return 0;
}
[此贴子已经被作者于2007-5-13 13:20:37编辑过]