- 分享
登录系统,供开发者使用
- @ 2026-4-25 20:38:03
我为大家提供一个登录系统,内容如下
#include <bits/stdc++.h>
using namespace std;
struct User {
string u,p;
};
void save(User x) {
ofstream f("users.txt", ios::app);
f<<x.u<<" "<<x.p<<endl;
}
bool exist(string s) {
ifstream f("users.txt");
string a,b;
while (f>>a>>b) if(a==s) return true;
return false;
}
bool check(string s,string t) {
ifstream f("users.txt");
string a,b;
while (f>>a>>b) if(a==s&&b==t) return true;
return false;
}
void zhengshidaima() {
// 此地方用于编写登录后续显示
cout<<"内容由故渊(才译翔)编写\n供开发者使用,谢谢";
}
void reg() {
User x;
cout<<"用户名: ";
cin>>x.u;
if (exist(x.u)) {
cout<<"已存在"<<endl;
return ;
}
cout<<"密码: ";
cin>>x.p;
save(x);
cout<<"成功"<< endl;
}
void login() {
string s,t;
cout<<"用户名: ";
cin>>s;
cout<<"密码: ";
cin>>t;
if (check(s,t)) {
cout<<"登录成功"<<endl;
zhengshidaima(); //跳转到编写正式代码区域,供开发者使用
} else {
cout<<"错误"<<endl;
}
}
int main() {
int c;
while (true) {
cout << "1.登录 2.注册 3.退出: ";
cin>>c;
if (c==1) {
login();
return 0;
}
if (c==2) reg();
if (c==3) return 0;
}
}
大家要是需要编写代码请在26~27行进行编写,谢谢,如有BUG请提出,要是有什么更好的代码分享,我也可以为你们提供
1 条评论
-
才译翔 @ 2026-4-25 20:38:59账户信息保存在本地
- 1