Please help me with the following code!! I want to have a file that contains a list of recipes, with the first line of the file being the number of recipes. To test out the file IO code, I wrote up this little test program, but it keeps overwriting the file!
How can I make it append the data to the end, but change the first line at the end?
Thanks so much!
sirSolarius
Code:
#include <iostream>
#include <fstream.h>
void main()
{
int *current, currenter;
currenter = 80;
current = ¤ter;
ofstream CoolFile("C:\\recipes.dat", ios::app);
if (CoolFile)
{
CoolFile << "I'm" << endl;
CoolFile << "One" << endl;
CoolFile << "Crazy" << endl;
CoolFile << "Guy" << endl;
CoolFile.close();
ofstream numberFile("C:\\recipes.dat");
numberFile.seekp(0);
numberFile << *current;
}
ifstream CoolFileIn("C:\\recipes.dat");
char stringer[100];
int x;
for (x=0; x<6;x++)
{
CoolFileIn >> stringer;
cout << "\n" << stringer;
}
}