Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<Windows.h>
- #include<fstream>
- #include<clocale>
- #include <conio.h>
- using namespace std;
- struct person {
- char login[30];
- int password;
- };
- int main() {
- setlocale(LC_ALL, "RUS");
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- cout << "Добро пожаловать в мою программу!\n1. Вход\n2. Регистрация\n3. Выход " << endl;
- int choise;
- cin >> choise;
- string path = "myfile.txt";
- fstream fout;
- fout.open(path, ios::in | ios::out);
- while (true)
- {
- switch (choise) {
- case 1://вход
- person second;
- bool log;
- log = false;
- cout << "Login:";
- cin >> second.login;
- cout << "Password:";
- cin >> second.password;
- if (fout.tellg() == -1) fout.clear(ios_base::goodbit);
- fout.seekg(ios::beg);
- while (!fout.eof()) {//ПАМАГИТИ!!!! CodeGod is fucking here
- person peps;
- fout.read((char*)&peps, sizeof(person));
- if (strcmp(peps.login, second.login) == 0 && peps.password == second.password)
- {
- log = true;
- break;
- }
- }
- if (log)
- cout << "Вы вошли в систему" << endl; //Вывести сообшение
- else
- cout << "Данные некорректные!" << endl; //Отказать в доступе
- break;
- case 2://регистрация
- bool sign_in;
- sign_in = false;
- while (!sign_in)
- {
- person first;
- cout << "Login:";
- cin >> first.login;
- cout << "Password:";
- cin >> first.password;
- if (fout.tellg() == -1) fout.clear(ios_base::goodbit);
- fout.seekg(ios_base::beg);
- bool found = false;
- while (!fout.eof())
- {
- person peps;
- fout.read((char*)&peps, sizeof(person));
- if (!strcmp(peps.login, first.login))
- {
- cout << "Такой пользоавтьель уже существует. Введите новые данные \n";
- found = true;
- break;
- }
- }
- if (!found)
- {
- fout.clear(ios_base::goodbit);
- if (fout.tellg() == 2) fout.seekg(ios_base::beg);
- sign_in = true;
- fout.write((char*)&first, sizeof(person));
- cout << "Регистрация прошла успешно \n";
- }
- }
- break;
- case 3:
- fout.close();
- return 0;
- break;
- default:
- cout << "Неправильный выбор!" << endl;
- }
- cout << "1. Вход\n2. Регистрация\n3. Выход " << endl;
- cin >> choise;
- }
- }
Add Comment
Please, Sign In to add comment