+ 2

Save Input to txt file

i used ofstream myFile; myFile.open(filename); cout<<"create a username"<<endl; cin>>username; myFile<< username << endl; I got it to save in the file, but it only saves to the first line, so it overwrite whatever was there. someone help

2nd Dec 2018, 10:07 PM
Michael Guidice
Michael Guidice - avatar
5 Answers
+ 2
Try to use the open mode append: myFile.open("filename", ios::app); it should open the file to append it so it should not overwrite!
2nd Dec 2018, 11:52 PM
Sekiro
Sekiro - avatar
+ 2
I still seem to be having the same problem. I don't think it's a problem with how I'm opening the file, but rather how I'm storing the info
3rd Dec 2018, 12:02 AM
Michael Guidice
Michael Guidice - avatar
+ 2
It worked ! THANK YOU SO MUCH
3rd Dec 2018, 1:43 AM
Michael Guidice
Michael Guidice - avatar
3rd Dec 2018, 12:40 AM
Sekiro
Sekiro - avatar
0
Glad I could help 😊 Happy coding!
3rd Dec 2018, 4:05 AM
Sekiro
Sekiro - avatar