c语言密码用*号代替并且按下另一键显示密码,也可以会删,删到(请输入:)这个地方就不能继续了
这个用putchar 替代printf就可以。可以参考Mysql输入密码的实现。
#include <conio.h>
#include <stdio.h>
#include<windows.h>
#include <time.h>
#include <string>
#include <algorithm>
using namespace std;
#pragma warning(disable:4996)
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
void main()
{
char ch;
string text;
cout << "请输入明文:" << endl;
do
{
ch = getch();
if (ch == 13) {
break;
}
if (ch == 8) {
system("cls");
cout << "请输入明文:" << endl;
text.pop_back();
for (int i = 0; i < text.size(); i++) {
putchar('*');
}
}
else {
text += ch;
putchar('*');
}
} while (ch != 13);
cout << endl << "密文为:" << endl;
cout << text << endl;
system("pause");
}
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632