void Load()
{
book *newptr,*p,*q;
char id [12];
string title;
string author;
int year;
float price;
ifstream file1;
head = NULL;
file1.open("books.txt");
if (file1.fail())
{
cout << "Error opening file.\n";
exit(1);
}
while (!file1.eof())
{
newptr = new book; //
file1.getline(id,12);
getline(file1,title);
getline(file1,author);
getline(file1,year);
file1.getline(price);
//copy values from the file to the newptr
newptr->id.assign (id) ;
newptr->tajuk.assign (title) ;
newptr->penulis.assign(author) ;
newptr->tahun.assign (year) ;
newptr->harga.assign(price) ;
if(head == NULL)
head = newptr;
else
{
p = head;
q = NULL;
while(p != NULL && p->id.compare(newptr->id)>0)
{
q = p;
p = p->next;
}
if(q == NULL)
{
newptr->next = head;
head = newptr;
}
else
{
newptr->next = p;
q->next = newptr;
}
}
}
file1.close();
return ;
}
void newdisplay()
{
system("cls");
char id [12];
string title;
string author;
int year;
float price;
ifstream file1;
file1.open("books.txt");
cout<<"________________________________________________________________________________________________________________"<<endl;
cout<<"\n\tID:\tTITLE:\tAUTHOR:\tYEAR:\tPRICE:<<endl;
cout<<"________________________________________________________________________________________________________________"<<endl;
if (file1.fail())
{
cout << "Error opening file.\n";
exit(1);
}
while (!file1.eof())
{
getline(file1,id);
getline(file1,title);
getline(file1,author);
getline(file1,year);
getline(file1,price);
cout <<"\n"<< id<<"\t"<<title<<"\t"<<author<<"\t"<<year<<"\t"<<price<<"\t"<<endl;
}
file1.close();
return ;
}
when i compile;
[Error] D:\My Documents\Downloads\file.cpp:370: no matching function for call to `ifstream::getline (_IO_istream_withassign &, int &)'
[Error] D:\C-FREE~1\mingw32\Include\G__~1\iostream.h:129: candidates are: class istream & istream::getline(char *, int, char = '\n')
[Error] D:\My Documents\Downloads\file.cpp:371: no matching function for call to `ifstream::getline (float &)'
[Error] D:\My Documents\Downloads\file.cpp:374: request for member `assign' in `newptr->book::id', which is of non-aggregate type `char[12]'
[Error] D:\My Documents\Downloads\file.cpp:377: request for member `assign' in `newptr->book::year', which is of non-aggregate type `int'
[Error] D:\My Documents\Downloads\file.cpp:389: request for member `compare' in `p->book::id', which is of non-aggregate type `char[12]'
[Error] D:\My Documents\Downloads\file.cpp:443: no matching function for call to `getline (ifstream &, char[12])'