关于atm登陆模块的相关问题,蹲详细解答

简单的atm登陆模块的设计和开发,(需假设用户名为abcd 123),密码不正确时需提示密码错误,直到输入正确的用户名及密码

#include <iostream>
#include <string>

struct User {
  std::string userName;
  std::string password;
};

User users[] = {{"abc", "123"}};

int main() {
  bool verified = false;
  while (!verified && std::cin) {
    std::string userName;
    std::string password;
    std::cout << "User Name: ";
    std::cin >> userName;
    std::cout << "Password: ";
    std::cin >> password;
    for (std::size_t i = 0; i < sizeof(users) / sizeof(User); i++) {
      if (users[i].userName == userName && users[i].password == password) {
        std::cout << "login successful\n";
        verified = true;
        break;
      } else {
        std::cerr << "Wrong user name or password\n";
      }
    }
  }
  return 0;
}