【发布时间】:2010-12-21 06:41:16
【问题描述】:
有什么简单的方法可以存储用户输入的密码同时仍然隐藏密码?
char password[9];
int i;
printf("Enter your password: ");
for (i=0;i<9;i++)
{
password[i] = getch();
printf("*");
}
for (i=0;i<9;i++)
printf("%c",password[i]);
getch();
}
我想存储密码,这样我就可以做一个简单的if (password[i] == root_password),这样正确的密码就会继续。
【问题讨论】:
-
您在 C++ 中使用
getch而不是cin.get的任何特殊原因? -
没有理由。找不到其他合适的方式。
-
@Cody: getch 不回显输入,不像典型的 cin.get()