#include <iostream>
#include <conio.h>
using namespace std;
int main() {
fflush(stdin);
cout << "请输入密码:";
int idx = 0;
char password[20], c;
while((c = getch()) != 13) { // 13是回车,8是删除
if(c == 8 && idx > 0) {
printf("\b \b");
idx--;
continue;
}
if(c != 8) {
password[idx++] = c;
putchar('*');
}
}
compare[idx] = '\0';
cout << "\n输入的密码为:" << password<< endl;
return 0;
}
C++在DOS中实现密码框
最新推荐文章于 2023-12-23 19:54:09 发布
本文介绍了一个使用C++编写的程序,它通过`getch()`函数实现用户输入密码,并用星号(*)隐藏输入字符。程序允许用户使用退格键删除已输入的字符,最后显示输入的完整密码。
1251

被折叠的 条评论
为什么被折叠?



