C++ 尝试在c+中开发用户登录代码+;

C++ 尝试在c+中开发用户登录代码+;,c++,C++,我正在一个项目中,我必须设置用户登录。用户数据存储在类结构的文件中。 这是我的登录功能: bool check_login(int n, string pass) { bool found = false; account ac; ifstream infile; infile.open("final.dat",ios::binary); if(!infile) { cout<<"File could not be op

我正在一个项目中,我必须设置用户登录。用户数据存储在类结构的文件中。 这是我的登录功能:

bool check_login(int n, string pass)
{
    bool found = false;
    account ac;
    ifstream infile;
    infile.open("final.dat",ios::binary);
    if(!infile)
    {
        cout<<"File could not be open !! Press any Key...";
        return false;
    }
    while(!infile.eof() && found==false)
    {
        infile.read(reinterpret_cast<char *> (&ac), sizeof(account));
        if(ac.retacno()==n)
        {
            if(pass.compare(ac.retpassword())==0)
            found=true;
            return found;
          }
    }
    infile.close();
    return found;
}

class account
{
        int acno;
        string password;
        string name;
        string address;
        char sex;
        string phonenumber;
    public:
        void create_account();  //function to get data from user
        void show_account() const;  //function to show data on screen
        void modify();  //function to add new data
        void withdraw(int,int); //function to accept amount and subtract from balance amount
        void donate(int,int);   //function to accept amount and add to balance amount
        void report() const;    //function to show data in tabular format
        int retacno() const;    //function to return account number
        string retpassword() const; //function to return password
};    
bool check\u登录(int n,字符串传递)
{
bool-found=false;
账户ac;
河流充填;
infle.open(“final.dat”,ios::binary);
如果(!infle)
{
在这里不能看到这个

infile.read(reinterpret_cast<char *> (&ac), sizeof(account));
infle.read(重新解释铸件(&ac),尺寸(账户));
对于类来说,将无法正常工作。您需要添加代码来序列化和反序列化您的帐户实例。现在,您将文件中的所有内容读入帐户实例,而无需运行任何成员构造函数(例如字符串)


例如,要序列化/反序列化,您可以覆盖
>
其中是
main()
?请显示
帐户的定义,好吗?将帐户转换为char*可能无效。@阿披舍克您最好编辑您的问题,然后添加不可读的代码作为注释。请编辑问题,而不是在注释中发布代码。