c++用户登录设计中出现的问题

来源:百度知道 编辑:UC知道 时间:2024/09/23 09:24:36
要求能够先注册,用户信息存入一个user.txt,然后再在登录的时候读取user.txt内部信息进行比较。我写的是这样的:
//user.h
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class user
{
private:
char name[16];
char password[20];
static int id;
public:
user(){id++;};
void Reg();
int login();
};
//user.cpp
#include<fstream>
#include<iostream>
#include<iomanip>
#include "user.h"
using namespace std;
int user::id=0;
void user::Reg()
{
cout<<"Register"<<endl;
cout<<"Account:";
cin>>name;
cout<<"Password:";
cin>>password;
ofstream regfile("user.txt",ios_base::app);
regfile<<name<<setw(10)<<password<<endl;
regfile.close();
cout<<"Register Success!"<<endl;
}
int

应该是这样的吧?
在for外面
...
if(password[h]=='\0')
{
loginfile.close();
return 1;
} // if password
} // if name
} // for
loginfile.close();
return 0;
} //user::login

建议把用户信息存入2进制文件,这样便于程序处理,而且保密性较好