I'm going to use what I've learned in File i/o to make a username collection where people can create users and log in. But I'm stuck on something. The way I did it before allowed people to override other users, so I need some code to detect wheter that username is detected.
A persons username is stored as username.txt and the password is inside the txt file.
This is what I've been trying
I need something to detect whether the text file already existsCode:#include <iostream> #include <windows.h> #include <stdlib.h> #include <fstream> using namespace std; void mainmenu(); void mainmenu() { string username; string option; cout<<"1)Create new Account\n"; cout<<"Choice: "; cin>>option; cin.ignore(); if ( option == "1" ) { cout<<"Enter your desired username: "; cin>>username; if ( !ofstream a_file () == username ) { cout<<"Enter Password"; Sleep(3000); } else { cout<<"Sorry that username is already taken"; Sleep(3000); } } int main() { mainmenu(); }
Thanks in Advance