Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- void register_1();
- void read(string login, string parol);
- void login();
- struct Users{
- string login;
- string parol;
- }users[100];
- void main(){
- setlocale(LC_ALL,"RUS");
- cout << "1.регистрация" <<endl;
- cout << "2.вход" <<endl;
- int a;
- cin >> a;
- switch(a){
- case 1: register_1();
- case 2: login();
- }
- }
- void register_1(){
- string login,parol;
- cout << "Введите логин:" <<endl;
- cin >> login;
- cout << "Введите пароль:" <<endl;
- cin >> parol;
- ofstream fout("users.txt",ios::app);
- fout << login<<" "<<parol<<endl;
- cout << "Регистрация прошла успешно!" <<endl;
- main();
- }
- void read(string login, string parol){
- ifstream fin("users.txt");
- for (int i=0;i<100;i++){
- fin >> users[i].login>>users[i].parol;
- }
- }
- void login(){
- string login,parol;
- cout << "Введите логин:" <<endl;
- cin >> login;
- cout << "Введите пароль:" <<endl;
- cin >> parol;
- read(login,parol);
- bool flag = true;
- for(int i=0;i<100;i++){
- if(login==users[i].login && parol==users[i].parol){
- cout << "Вы успешно вошли!" <<endl;
- flag = false;
- break;
- }
- }
- if(flag==true){
- cout <<"Пароль либо логин введены неверно!"<<endl;
- }
- system("pause");
- main();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement