c语言密码用*号代替并且按下另一键显示密码,也可以会删,删到(请输入:)这个地方就不能继续了
2条回答 默认 最新
- CSDN专家-Time 2021-06-12 17:19关注
这个用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"); }
解决 无用评论 打赏 举报