Привет, я делаю код входа и выхода.
Я уже все выяснил, главная ошибка заключается в том, что проверка на одно и то же имя пользователя при регистрации не работает. Пожалуйста помочь
Что я уже пробовал:
#include <iostream> #include <iomanip> #include <fstream> #include <string> #include<stdlib.h> #include<time.h> #include <cstdlib> #include "conio.h" using namespace std; int check(string username) { cin >> username; string data1, data2; ifstream infile; infile.open("profile.txt", ios::app); getline(infile, data1); if (username == data1) { cout << "Username exits" << endl; cout << "Enter new username: "; cin >> username; return check(username); } else { } } int main() { int z; FIRST: cout << "Press 1 to Create Account" << endl; cout << "Press 2 to Log In " << endl; cout << "your choice: "; VALID: cin >> z; switch (z) { case 1: { string name, pas, repas; cout << "Enter Your username:"; cin >> name; check(name); cout << "Enter Password(Atleast 5 characters) :"; START1: cin >> pas; if (pas.length() < 5) { cout << "Enter a password of atleast 5 characters : "; goto START1; } else cout << "Re-write Password to confirm:"; START2: cin >> repas; if (repas != pas) { cout << "Re-Enter the Password !"; goto START2; } else cout << "Profile Created With the User Name " << name << endl; // cout on the console ofstream myfile; myfile.open("profile.txt",ios::app); myfile << name << endl; myfile << pas << endl; myfile.close(); _getch(); system("CLS"); goto FIRST; } case 2: // For logging in { system("CLS"); cout << "Welcome to Login screen\n\m"; char pass[32]; string name, pas; START3: cout << "Enter Username:"; cin >> name; string data1, data2; ifstream infile; infile.open("profile.txt",ios::app); getline(infile, data1); if (name != data1) { cout << "Invalid User Name.Try Again\n"; goto START3; } else cout << "User Name Found\n"; cout << "Enter Password : "; int i = 0; char a; for (i = 0;;) { a = _getch(); if ((a >= 'a'&&a <= 'z') || (a >= 'A'&&a <= 'Z') || (a >= '0'&&a <= '9')) { pass[i] = a; ++i; cout << "*"; } if (a == '\b'&&i >= 1) { cout << "\b \b"; --i; } if (a == '\r') { pass[i] = '\0'; break; } } getline(infile, data2); START4: if (pass == data2) { cout << "You are Logged In"; _getch(); } else { cout << "Invalid Password\nEnter Again:"; char pass[32]; cout << "Enter Password : "; int i = 0; char a; for (i = 0;;) { a = _getch(); if ((a >= 'a'&&a <= 'z') || (a >= 'A'&&a <= 'Z') || (a >= '0'&&a <= '9')) { pass[i] = a; ++i; cout << "*"; } if (a == '\b'&&i >= 1) { cout << "\b \b"; --i; } if (a == '\r') { pass[i] = '\0'; break; } } goto START4; } infile.close(); break; } default: { cout << "Please Enter Valid Number !"; goto VALID; } } }