User.h
#pragma once
#include <iostream>
#include <string>
#include <map>
#include <fstream>
#define FILENAME "Account.txt"
using namespace std;
class User
{
public:
ifstream fin;
ofstream fout;
User() = default;
bool checkIfNum(string str);
void read();
void save();
void registration();
void login();
void modify();
void logout();
private:
static map<string, string> mapUser;
string m_acc;
string m_psw;
};
User.cpp
#include "User.h"
map<string, string> User::mapUser;
bool User::checkIfNum(string str)
{
for (auto c: str)
{
if (c >= 48 && c <= 57)
continue;
else
{
cout << "Please enter number" << endl;
return false;
}
}
return true;
}
void User::read()
{
fin.open(FILENAME, ios::in);
if (!fin.is_open())
{
cout << "No accounts" << endl;
return;
}
while (!fin.eof())
{
fin >> m_acc >> m_psw;
mapUser.insert(make_pair(m_acc, m_psw));
}
fin.close();
}
void User::save()
{
fout.open(FILENAME, ios::out);
for (auto it = mapUser.begin(); it != mapUser.end(); it++)
fout << it->first << " " << it->second << endl;
fout.close();
}
void User::registration()
{
this->read();
string pswForCheck;
while (true)
{
cout << "Please enter the account :"