当前位置:首页 > 通信资讯 > 正文

c++实现登录注册功能(c++注册登录系统代码)

C++控制台实现简单的注册登录,供大家参考,具体内容如下

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 #include<iostream> #include<string> #include <vector> #include <conio.h> void Display();//调用display显示switch()界面 void Register();//注册 void Enter();//登录 using namespace std; class user{ private: string ID; string Name; string Email; string Password; public: user(){}; void Register(); void Enter(); } ; vector<user> people; void user:: Register()//注册 { string pw1; string pw2; user person; cout<<"请设置您的ID:"; flag: cin>>person.ID; for(int i=0;i<people.size();i++){ if(people.at(i).ID==person.ID){ cout<<"该ID已存在,请重新设置:"; goto flag; } } cout<<"请设置您的用户名:"; cin>>person.Name; cout<<"请绑定您的邮箱:"; cin>>person.Email; cout<<"请设置您的密码:"; flag0: cin>>pw1; cout<<"请再次确认您的密码:"; cin>>pw2; if(pw1!=pw2) { cout<<"前后两次输入密码不一致,请重新设置密码:"; goto flag0; } cout<<"注册成功!"<<endl; person.Password=pw1; people.push_back(person); Display(); } void user::Enter()//登录 { cout<<"请输入您的ID:"; flag1: string id; string pwd; cin>>id; for(int i=0;i<people.size();i++){//验证ID是否存在 int tk=1;tk++; if(people.at(i).ID==id){ tk=2; cout<<"请输入您的密码:"; flag2: cin>>pwd; if(people.at(i).Password!=pwd){ cout<<"密码错误,请重新输入:"; goto flag2; } cout<<"登录成功!"<<endl; cout<<" (1)Information查看信息\n (2)Exit退出\n\nChoice:"; int choice;//选择界面 cin>>choice; switch(choice) { case 1://查看信息 cout<<"您的ID为:"<<people.at(i).ID<<endl; cout<<"您的密码为:"<<people.at(i).Password<<endl; cout<<"您的用户名为:"<<people.at(i).Name<<endl; cout<<"您的邮箱为:"<<people.at(i).Email<<endl; Display(); case 2://退出 exit(EXIT_FAILURE); } } } cout<<"该ID不存在,请重新输入:"; goto flag1; } void Display()//界面 { cout<<" (1)Register注册\n (2)Enter登录\n (3)Exit退出\n\nChoice:"; int choice;//选择界面 user u; cin>>choice; switch(choice) { case 1://注册 u.Register();//调用函数 break; case 2://登录 u.Enter();//调用函数 break; case 3://退出 exit(EXIT_FAILURE); } } int main() { Display();//显示界面  1注册;2登录;3退出 cin.get(); return 0; }

程序运行如下图所示:

c++实现登录注册功能(c++注册登录系统代码)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。