Hi everyone,
i have a problem reading records from file
i can write to th efile but cannot read back
can any one help wit this please
Code:
void writeAppointmenRecords( )
{
int index;
//create and open an output text file
fstream outfile("C:\\Documents and Settings\\zafer\\Desktop\\AppointmenRecords.txt", ios::app);
// Check if file is opened
if(!outfile) //return true if file is not opened
{ cout<<"\nFailed to open file!!!!\n";
cout<<"\nPress any key to proceed ";
cin.get();
}
for (index=0; index<currentSize; index++)
{
outfile<<AppointmenList[index].name;
outfile<<setw(15)<<AppointmenList[index].description;
outfile<<setw(15)<<AppointmenList[index].appdate.day;
outfile<<"/"<<AppointmenList[index].appdate.mounth;
outfile<<"/"<<AppointmenList[index].appdate.year;
outfile<<setw(15)<<AppointmenList[index].time<<endl;
}
//write values to file in an 15 characters field.
outfile.close( ); // close file
cin.get();
}
void readAppointmenRecords( )
{
currentSize=0;
//create a stream and open the file 'AppointmenRecords.txt' for input
fstream infile("C:\\Documents and Settings\\zafer\\Desktop\\AppointmenRecords.txt", ios::in);
// check if file is opened
if(!infile) //return true if file is not opened
{ cout<<"\nFailed to open file!!!!\n";
//indicate program failed
cin.get();
}
while (!infile.eof( )) //eof( ) End Of File function. Returns false if end file reached
{
getline(infile, AppointmenList[currentSize].name);
getline(infile, AppointmenList[currentSize].description);
infile.get();
infile>>AppointmenList[currentSize].appdate.day;
infile>>AppointmenList[currentSize].appdate.mounth;
infile>>AppointmenList[currentSize].appdate.year;
getline(infile, AppointmenList[currentSize].time);
currentSize+=1;
}
infile.close( ); // close file
currentSize = currentSize -1;
cin.get();
}