Alright, so i'm trying to make a type of database using file i/o where you type in a username and password and it writes it to database.txt... The issue is, i'm trying to find a correct and clean way of reading, or 'searching' for the username and password and compares it with what the user put. Here is what I have so far.
(I know it is sloppy, but i typed it up in 5 minutes so ya know. What it does is uses a menu and switch/case for options 1-4, option 1 is where i need help at, to find out how to search for the username correctly. i'm pretty good with strings, its just i really have no clue how i'd do this properly.)
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
char* Username = new char[255];
char* Password = new char[255];
char* User = new char[255];
void Join()
{
ofstream DataBase("DataBase.txt", ios::app);
cout << "Welcome New Member, Please Enter a New Username and Password:\n\n";
cout << "Username: ";
cin >> Username;
cout << "\nPassword: ";
cin >> Password;
DataBase << Username << "\n";
DataBase << Password << "\n\n";
cout << "\nSaved To Database!\n";
DataBase.close();
delete [] Username;
delete [] Password;
}
void Login() {
ifstream DataBase("DataBase.txt");
cout << "Welcome Member, Please Enter Your Username and Password:\n\n";
cout << "Username: ";
cin >> User;
DataBase >> Username;
if (Username==User) cout << "\nUsername Correct!";
else cout << "\nUsername Incorrect!";
delete [] User;
delete [] Username;
delete [] Password;
}
void About() {
}
int main(int argc, char *argv[])
{
int option;
cout << "DataBase v1.00 BETA!\n\n";
cout << "1.Login\n";
cout << "2.Sign-Up\n";
cout << "3.About\n";
cout << "4.Exit\n\n";
cout << "Option(1-4): ";
cin >> option;
switch (option) {
case 1:
Login();
break;
case 2:
Join();
break;
case 3:
About();
break;
case 4:
break;
default:
cout << "Not An Option!";
break;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Thanks in advance for any advice, or if anyone can point me in the right direction, i'm much appreciative.