#include<iostream>
#include<fstream>
#include<windows.h>
using namespace std;
string a,b;
void showmain()
{
cout<<"用户管理系统"<<endl;
cout<<"1.用户注册"<<endl;
cout<<"2.用户登录"<<endl;
cout<<"0.退出"<<endl;
}
void Register()
{
ofstream of;
of.open("f2.txt",ios::app);
cout<<"请输入用户名:"<<endl;
cin>>a;
cout<<"请输入密码:"<<endl;
cin>>b;
of<<a<<" "<<b<<endl;
of.close();
}
void login()
{
cout<<"用户登录"<<endl;
cout<<"用户名:";
cin>>a;
cout<<"密码:";
cin>>b;
string a1,b1;
ifstream infile ("f2.txt",ios::in);
int flag=0;
while(infile>>a1>>b1&&!flag)
{
if(a==a1&&b1==b)
{
flag=1;
cout<<"登陆成功"<<endl;
}
}
if(!flag) cout<<"登陆失败"<<endl;
}
int main()
{
int flag=1;
int choose;
while(flag)
{
showmain();
cin>>choose;
switch(choose)
{
case 1:
Register();
break;
case 2:
login();
break;
case 0:
flag=0;
break;
}
system("pause");
system("cls");
}
return 0;
}
文件操作
最新推荐文章于 2024-05-18 08:10:31 发布