Code:
int ListOfObjects::save( ostream & out )
{
ofstream ObjectsFile( "Objects.dat", ios::out);
int Index = 0;
if( !ObjectsFile )
{
cerr << "File could not be opened" << endl;
}
for( Index = 0; Index < cCount; Index++ )
{
ObjectsFile << cList[Index];
}
return 0;
}
You have a functin parametr that you never use. Plus I would do it another way. This is how I would implement a saving function:
Code:
#include <string.h> // strcpy()
#include <fstream.h> // file i/o
class Stuff
{
public:
Stuff();
int save(Stuff *sPtr);
char string[10];
char stringTwo[10];
int num;
};
/* Constructor */
Stuff::Stuff()
{
for(int i = 0; i < 10; i++)
{
string[i] = 0;
stringTwo[i] = 0;
}
num = 0;
}
/* Save Member Function */
int Stuff::save(Stuff *sPtr)
{
ofstream outfile("Outfile.txt");
if( !outfile )
{
cerr << "Couldn't open file" << endl;
return 1;
}
outfile << sPtr->string << endl
<< sPtr->stringTwo << endl
<< sPtr->num << endl;
outfile.close(); // I don't trust destructors
return 0;
}
int main()
{
Stuff stuffObject;
strcpy(stuffObject.string, "Hello");
strcpy(stuffObject.stringTwo, "Yo");
stuffObject.num = 10;
stuffObject.save(&stuffObject);
return 0;
}
Hope that helps.