C++/file handling in c++
1st of All Happy New Year Sir!...My question is about file handling i want to make a data of users entering there user name and password and storing that to a file.txt....then after that adding data related only to that username ..after adding data that should be stored in that file..when user again comes and gives his username and password so after comparing if it comes to be true i mean if both are matching then program should display it's data.
i am a beginner to c++ and has just reached topic file handling i know about files like what streams should be used and how to open or close file and how to append or edit....but i just want to know how to register a new user and then storing data of that specific user.
sorry for such a long question i will be very thankful if u would answer this and satisfy me.
Hi Irshad, thank you for the question.
It sounds to me like you need a struct for your User and associated data in code. Here is a snippet of some pseudo code you can use to get started:
string name, password;
// somewhere in code
string name, pword;
cout << "Enter the user name: ";
cin >> name;
cout << "Enter the password: ";
cin >> pword;
// open the file
cout << "Failed to open the data file" << endl;
bool foundUser = false;
string tempName, tempPass;
in >> tempName;
in >> tempPass;
in >> tempData;
if(tempName == name)
user.name = tempName;
user.password = tempPass;
user.someData = tempData;
// Check the matching passwords here also
// and perform security and error checking
That is how I would approach the problem. Please let me know if you have any other questions.
I hope this information was helpful.