Your mistake was correctly spot by
Rick York.
In any case, you code is very C-like. I give a (very simplified) example of a different approach:
#include <iostream>
#include <fstream>
using namespace std;
enum class AccountType
{
Current,
Deposit
};
class Account
{
string name;
AccountType type;
public:
Account(string name, AccountType type):
name(name), type(type)
{}
friend ostream & operator << (ostream & os, const Account & account);
friend istream & operator >> (istream & is, Account & account);
};
ostream & operator << (ostream & os, const Account & account)
{
os << account.name << " " << static_cast<int>(account.type) << endl;
return os;
}
istream & operator >> (istream & is, Account & account)
{
int type;
is >> account.name >> type;
account.type = static_cast<AccountType>(type);
return is;
}
int main()
{
Account account_foo("foo", AccountType::Deposit);
{
ofstream ofs("foo.txt");
ofs << account_foo;
}
Account account_boo("boo", AccountType::Current);
ifstream ifs("foo.txt");
ifs >> account_boo;
cout << account_boo << endl;
}