Need help with text files.

I want to try to make a basic program that lets you enter your own username and password, and it will store it, and will allow you to log in with it later. I have this so far, but when I re-run the program the previous usernames and passwords in the text file are replaced, and I am unable to figure out how to re access/check the text file. This is what I have so far. Any help will be appreciated.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
string uname;
string upass;
string username;
string password;
int choice;
fstream file;

cout << "Hello. Please enter your account info, or type 0 and enter to create an account. \n";
cin >> choice;
if (choice == 0)
{
cout << "\n\n Please enter your new username.\n\n";
file.open("info.txt", ios::out);
cin >> uname;
file << "Username : " << uname << endl;

cout << "Please enter your new password.\n\n";

cin >> upass;
file << "Password : " << upass << endl;
file << " " << endl;
file.close();
cout << "Thank you. You may now log in.";

}

return 0;
}

Thanks in advanced.
They are overwritten. When you open the file you start outputting data at the beginning of it, and the previous contents are not pushed away. To open the file and place the put pointer at the end you can use the 'ate' openmode flag
http://cplusplus.com/reference/ios/ios_base/openmode/
Topic archived. No new replies allowed.