【发布时间】:2017-01-01 14:53:13
【问题描述】:
**我想在控制台输入时隐藏密码**
bool User::isLogIn(){
string username, password, file_line;
cout << "Enter username:";
cin >> username;
cout << "Enter password:";
cin >> password;
ifstream infile;
infile.open("users.txt");
if (!infile.is_open()){
cout << "Error while opening the file...";
}
else{
string str;
while (getline(infile, str)){
vector<string> newVector = split(str);
string username_from_file = newVector[1];
string password_from_file = newVector[3];
if ((username_from_file.compare(username) == 0) && (password_from_file.compare(password)) == 0){
return true;
}
}
}
return false;
}
谁能告诉我怎么做才能在输入密码时显示为“*”?
【问题讨论】:
-
您可能需要操作系统的帮助。一种方法是使用操作系统 API 拦截所有按键,然后将
*发送到控制台。
标签: c++