I don't know how to go on from here. I don't know how to get the password to write nor when you already have an account, how to read the information and have the program use it.
First of all, how do I start to write to a file? Second, how do I set the append parameter to true? Third how do I read that file? Finally, how do I get the program to use the stuff that it just read?
When you go to open a file, the computer first checks to see if that file exists. If it doesn't exist (in the directory you specify), it will create a file with that name.
1 2 3 4
ofstream myfile; //Creates an output file stream object named myfile
myfile.open ("example.txt"); //Opens, or in this case creates, a file named example.txt
myfile << "Writing this to a file.\n"; //Now this writes to this file. You use the same operator as you would for cout
myfile.close(); //This closes your file. You always want to close the file when you're done with it
Now with just a slight modification, we can tell your program to append (write to the end of the file).
1 2 3
...
myfile.open("example.text", ios::app);
...
Now if you want to input information from this file, you do it in almost the same way as cin.
1 2 3 4 5 6 7 8 9 10 11
string line;
ifstream myfile ("example.txt");
if (myfile.is_open()) //Checks to make sure the file is indeed open
{
while ( myfile.good() ) //Remains true as long as you are not at the end of the file, or eof
{
getline (myfile,line); //This will loop through, assign each line to line var, and cout it.
cout << line << endl;
}
myfile.close(); //Closes file
}