// Writes to file
d_file << "The 4 numbers having the Highest Frequencies are:" << endl << endl;
d_file << indexoffirst+1 << " = " << first << ", " << indexofsecond+1 << " = " << second << ", " << indexofthird+1 << " = " << third << ", " << indexoffourth+1 << " = " << fourth << endl <<endl;
d_file << endl << endl;
d_file.close(); // Close the file stream explicitly
[/c++]
I then re-sorted the same file to find the 4 numbers having the lowest frequencies. again, I wrote the 4 numbers on the screen, then I tried to reopen the same file to update/append the new data into the file using:
Replace [c++] and [/c++] with [code] and [/code]
You had the right idea ;)
As for your problem, you used std::ios::app but you forgot to use std::ios::out! It should look like this: MyFile.open("MyFile.txt", std::ios::app|std::ios::out);
Why is this needed? Well, I suppose because it is to be consistent with std::fstream where it could be either in, out, or both.
I made the changes, but it still didn't update/append the new data to the file. In the build window I get the following:
1 2 3 4 5 6 7 8
'Mega_Money.exe': Loaded 'C:\Users\Therry.arkashea1-PC\Documents\Visual Studio 2010\Projects\Mega_Money\Debug\Mega_Money.exe', Symbols loaded.
'Mega_Money.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'Mega_Money.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'Mega_Money.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'Mega_Money.exe': Loaded 'C:\Program Files\AVAST Software\Avast\snxhk.dll', Cannot find or open the PDB file
'Mega_Money.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'Mega_Money.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
The program '[3456] Mega_Money.exe: Native' has exited with code 0 (0x0).