Hi
im trying to write records to the file and with other option
read from that file.
i can write to the file but i want to keep the old entry
this codes keep refreshing the file with the new one,
and i cannot read from file.
anyone can help whit this plase?????????
void writeAppointmenRecords( )
{
int index;
//create and open an output text file
ofstream outfile("C:\\Documents and Settings\\zafer\\Desktop\\AppointmenRecords.txt", ios::out);
// 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(10)<<AppointmenList[index].description;
outfile<<setw(5)<<AppointmenList[index].appdate.day;
outfile<<"/"<<AppointmenList[index].appdate.mounth;
outfile<<"/"<<AppointmenList[index].appdate.year;
outfile<<setw(8)<<AppointmenList[index].time<<endl;
}
//option2: write values to file in an 8 characters field.
outfile.close( ); // close file
cin.get();
}
void readAppointmenRecords( )
{ //create a stream and open the file 'AppointmenRecords.txt' for input
ifstream 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);
}
infile.close( ); // close file
cin.get();
}
hi a made cupple of changes on my codes,
i m still having truble with reading can anybody help me with this or
can anyone give me some exaples or something so i can try to see my mistakes
thanks
void writeAppointmenRecords( )
{
int index;
//create and open an output text file
ofstream 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
ifstream 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( ) 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();
}