Writing to a file.

Hello,i am trying to write a file with input name from the program and then to write in the file something else..
How can i create the file with the extension .txt?
How can i hide the password when i write it?
1
2
3
4
5
6
7
8
9
10
11
cout << "Please enter your username" << endl;
cin >> username;
cout << "Enter your password" << endl;
cin >> password;
ofstream myfile(username); // its saving the file with the input name
if (myfile.is_open())
{
    	myfile << password; // its showing the password
    	myfile << "Second\n";
    	myfile.close();
}
Last edited on
This should help.
http://www.cplusplus.com/doc/tutorial/files/

Best of luck :)
Thanks for reply but i already read that.
If i use like "example.txt" the file will be called example.
I can`t add to username .txt extension becouse i get an error.

1
2
3
cout << "Please enter your username" << endl;
cin >> username;
ofstream myfile(username); // Here i can`t put .txt,i need another way.. 
Topic archived. No new replies allowed.