So I created a program , when you write " user.create " in the console it will tell you to input a name and a password , after that , the username and the password are being written in the text file " nice.txt " , but every time you start the program , " nice.txt " is cleared , how can I leave text there and read it when I need to ?!
here is the sample code :
#include <iostream>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream file_to_create;
file_to_create.open("nice.txt");
ifstream read("nice.txt");
ofstream out("nice.txt");
string input = " ";
while (1) {
cin >> input;
if (input == "app.exit")
return 0;
else if (input == "user.create") {
string name, password;
cout << "create user->\n";
cout << "name:";
cin >> name;
cout << "password:";
cin >> password;
out << name << '\n' << password << '\n';
cout << "user created.\n";
} else if (input == "user.access") {
string name, password;
cout << "access user->\n";
cout << "name:";
cin >> name;
cout << "password:";
cin >> password;
string look_name, look_password;
bool found = 0;
while (read >> look_name >> look_password) {
if (look_name == name && look_password == password) {
cout << "user " << look_name << " is now connected.\n";
found = 1;
}
}
if (!found)cout << "user not found.\n";
}
}
}
basically when you type in " user.access " it should read text from " nice.txt " which is empty because it's cleared every time you execute the .exe