I was wondering if anyone can give me tips on how to overwrite/update a .txt file. I give the user the option to add/delete data in a .txt file, and I want to be able to over write the .txt file with the changes they make. This is what I have, and it's not working.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void writeData(int& count)
{
ofstream aptInfo("RENTALS.TXT");
if (aptInfo.is_open())
{
for (int i = 0; i < count; i++)
{
aptInfo << array1[i].phoneNum << " " << array1[i].price << " " << array1[i].vacancy << endl;
//writes data to file
}
}
else
cout << "Could not open file. \n";
}
SamuelAdams, I am trying to enable the user to edit the txt file by adding, or deleting data. How it should work is the I load the data into array1[] from the .txt file, the user deletes/adds data into the array1[], then I would like to be able to write array1[] into the same txt file that is originally loaded into the array.
The int& in line 250 is there because I thought I would need it. It should be just a int.
The program should be able to loop through until the user wants to exit. So the user should be able to add/delete listings over and over, until he/she wants to close the program.
1. Load file into array and close file
2. Modify array as requested by user
3. Write array back to an std::ofstream file and close file
What part is causing your trouble?