#include<string.h>
#include<fstream.h>
class User
{
private:
char uid[10],pid[10];
public:
User(char u[],char p[])
{
strcpy(uid,u);
strcpy(pid,p);
}
};
void reg()
{
char u[10],p[10];
cout<<"\n请输用户名:";
cin>>u;
cout<<"\n请输密码: ";
cin>>p;
User myself(u,p);
fstream file;
file.open("text.txt",ios::app);
file.write((char *)&myself,sizeof(myself));
file.close();
cout<<"!!!!!!恭喜您成为本会员!!!!!!\n";
cout<<"-----------------\n\n";
}
void keeg()
{
char a[10],b[10];
cout<<"\n请输用户名:";
cin>>a;
cout<<"\n请输密码: ";
cin>>b;
User myself(a,b);
fstream file;
file.open("text.txt",ios::in);
file.read((char *)&myself,sizeof(myself));
while(!file.eof())
{
file.read((char *)&myself,sizeof(myself));
cout<<"用户名:"<<a<<endl;
cout<<"密码: "<<b<<endl;
}
file.close();
}
void main()
{
int a;
while(1)
{
cout<<"请选择您要执行的程序.\n";
cout<<"---------------------\n";
cout<<"1-创建用户\n";
cout<<"2-登录\n";
cout<<"0-退出\n";
cout<<"请输入0~2的数字";
cin>>a;
switch(a)
{
case(1):
reg();
break;
case(2):
keeg();
break;
case(0):
return;
}
}
}