在屏幕输入时密码用*号代替
密码为123时为高级玩家
321时为超级玩家
6条回答 默认 最新
- 白色一大坨 2018-05-17 09:39关注
#include <conio.h> #include <iostream> using namespace std; int main() { char* password; int length = 3; password = new char[length + 1]; char* p = NULL; int count = 0; cout << "Input password : "; p = password; count = 0; //fflush(stdin); while (((*p = getch()) != 13) && count < length) { // 这里不是'\n'(10), new line // 而是'\r'(13), reback. 即是按下回车键,好像这个东西是linux的. // 主要是与getch这个函数有关. putch('*'); fflush(stdin); p++; count++; } password[count] = '\0'; cout << endl; if (strcmp(password, "123") == 0) { cout << "高级玩家" << endl; } else if (strcmp(password, "321") == 0) { cout << "超级玩家" << endl; } else { cout << "普通玩家" << endl; } delete []password; password = NULL; system("pause"); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报