1234567891011121314151617181920
fstream f; int itemnumber,availability,n; string author,title; f.open("file.txt",ios::ate); cout<<"Enter the number of additional books: "; cin>>n; for(int i=0;i<n;i++) { cout<<"Enter item number: "; cin>>itemnumber; cin.get(); cout<<"Enter title: "; getline(cin,title); cout<<"Enter author: "; getline(cin,author); cout<<"Enter availability:"; cin>>availability; f<<itemnumber<<" "<<title<<", "<<author<<", "<<availability<<endl; } f.close();
123456
f.open("file.txt",ios::ate); if (!f) { perror(nullptr); // include <cstdio> return errno; }
f.open("file.txt",ios::ate); if (!f) { perror(nullptr); // include <cstdio> return; }