error in reading data file

#include<fstream.h>
#include<string.h>
#include<conio.h>
class record
{
char title[20],author[10],member[10];
int status;
public:
int code;
record()
{
status=0;
}
void getdata()
{
cout<<"Input Unique Book Code: ";
cin>>code;
cout<<"Input title of book: ";
cin>>title;
cout<<"Input name of author: ";
cin>>author;
}
void showdata()
{
cout<<"\nUnique Book Code: "<<code;
cout<<"\nBook title: "<<title;
cout<<"\nAuthored by: "<<author;
if(status==0)
cout<<"\n<This title is currently available.>";
else
cout<<"\n<This title is currently unavailable.>";
}
};
void main()
{
/*Program to input information in file, retrieve data from file,
modify data present on file, delete data from file and insert
new information*/
//Library Client
restart:
clrscr();
cout<<"\t\t*\t\t+Library Records+\t\t*\n";
cout<<"\n\nMENU:\n\n";
cout<<" 1. Search book details in database\n";
cout<<" 2. Issue Book(s)\n";
cout<<" 3. Return Book(s)\n";
cout<<" 4. Add new book(s) to database\n";
cout<<" 5. Display all records\n";
cout<<" 6. Delete lost/old book(s) from database\n";
cout<<" 7. Quit program\n";
cout<<"\nInput the serial number of your choice: ";
int x;
cin>>x;
clrscr();
record book;
fstream file("data.txt",ios::in|ios::out|ios::ate);
switch(x)
{
case 1: cout<<"\nYou will be redirected to the main menu!";
break;
case 2: cout<<"\nYou will be redirected to the main menu!";
break;
case 3: cout<<"\nYou will be redirected to the main menu!";
break;
case 4: char ans='y';
while(ans=='y'||ans=='Y')
{
book.getdata();
file.write((char*)&book,sizeof(book));
cout<<"Want to enter more records?(Y/N) ";
cin>>ans;
clrscr();
}
file.close();
cout<<"\nYou will be redirected to the main menu!";
break;
case 5: file.seekg(0);
while(file)
{
file.read((char*)&book,sizeof(record));
book.showdata();
}
file.close();
cout<<"\nYou will be redirected to the main menu!";
break;
case 6: cout<<"\nYou will be redirected to the main menu!";
break;
case 7: goto end;
default: cout<<"\nError! Unrecognized Input...";
cout<<"\nYou will be redirected to the main menu!";
}
goto restart;
end:
}
i cannot read file. the prog is incomplete. i cannot understand the error in case 5.
Last edited on
i figured it out. added stdlib.h and used system("PAUSE"). i wasted 3 hours on this >.<
Topic archived. No new replies allowed.