以下是我写的参考(输入密码时只能看到*)#include <cstdio>#include <cstring>#include <conio.h>void inputpassword(char pass[]){ int i=0; char ch; while(1) { ch=getch(); if(ch!='\r') { if(ch!='\b'){ pass[i]=ch; i++; printf("*"); }else{ if(i>0){ i--; printf("\b \b"); } } }else{ break; } } pass[i]='\0'; printf("\n");}int main(){ char p[20]; printf("请输入密码:\n"); inputpassword(p); if(strcmp(p,"asd123")==0) printf("密码正确\n"); else printf("密码错!\n"); return 0; }