Hi everyone
I am currently learning C++ and i am writing lots of small bits of code to get praticed in coding in C++.
i am working on a user system atm which takes a signup from the user and puts it in a text file so the user and login after or delete there account.
however i am having some issues. one issue the first way i coded it it was only letting me login once before it could find the text in the file. so i setup a new thing that i was about to start. but i dont know how to read what i want from the file without calling on my predfined strings password and username.
i manged to call out the text in the file but i want to be able to take the text and split it up into parts so i can compare it with what the user has put in.
so i dcided i look in to flat file databases but i couldnt find anything that helped me figure it out in c++.
this is what i have coded so far (this code doesnt work atm it was alted when i was trying to print out the test in the file created. it also has a few bugs that i havent iorned out yet)
#include <iostream>
#include <fstream>
using namespace std;
char username[50];
char password[50];
char password2[50];
char username2[50];
ofstream users("intblonkers.txt", ios::app);
ifstream users_b;
void SignUp() {
int check = 5;
cout << "please enter a username: ";
cin.getline(username, 50, '\n');
users << username << "~";
cout << "please enter a password: ";
cin.getline(password, 50, '\n');
users << password << "~";
cout << "thank you for signing up.\n";
users.close();
}
void login() {
int a = 5;
char account[50];
do {
cout << "Please enter your Username: ";
cin.getline(username2, 50, '\n');
cout << "please enter you Password: ";
cin.getline(password2, 50, '\n');
users_b.open("intblonkers.txt", ios::app);
users_b.seekg(ios::beg);
users_b >> account;
cout << account << '\n';
if (strcmp(password, password2) == 0 && strcmp(username, username2) == 0)
{
cout << "thank you for loging in this programe hasnt been finished yet but be shore to keep checking it out.\n";
a = 0;
}
else
{
cout << "you have entered a wronge username or password please try again.\n";
}
} while (a != 0);
}
void accountremove() {
int input;
int a = 0;
do {
cout << "If you have created 2 accouts the login will know longer work. Please delete your account and make a new one.\n";
cout << "1. go back.\n" "2. Delete account.\n";
cout << "Selection: ";
cin >> input;
cin.ignore();
switch (input) {
case 1:
{
a = 0;
break;
}
case 2:
{
a = 0;
users.open("intblonkers.txt", ios::trunc);
cout << "you have successfully deletted your account.\n";
break;
}
default:
{
cout << "your selection was incorrect please try again.\n";
break;
}
}
}while (a != 0);
}
int main() {
int input;
int a = 5;
do {
cout << "1. login.\n" "2. Sign up.\n" "3. Delete Accout.\n" "4. Quit.\n";
cout << "Selection: ";
cin >> input;
cin.ignore();
switch (input) {
case 1:
{
login();
break;
}
case 2:
{
SignUp();
break;
}
case 3:
{
accountremove();
break;
}
case 4:
{
cout << "good bye.\n";
a = 0;
}
default:
{
cout << "you have entered a incorrect value please try again.\n";
break;
}
}
} while (a != 0);
}
was wondering is anybody could help me to understand how to take a string and break it up.
or how to manage a flat file database.
atm i have set it to take the user input for password and username and put a ~ after it. like cgcgames~test~
was wondering how to take that string and split it up so that i can look at each part sepretatly.
also would like to know how to take more then one input so that you can make more the one account. atm it keeps the data but obvosily i dont know how to manage the data in the file so the program can read whats in the file and compare it to user input.
any help would be great :)
thank you,
Jordan