hi everyone
i am having problem with read from file, i can write to the filr but can not read from file
can anyone have a look at my codes or give me some examples so i can have look and try to see mt mistakes thanksCode: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(); }



LinkBack URL
About LinkBacks



if you want you can run it and see yourself thanks.