I m getting the message
" function seekg() needs a prototype "
even though i have included:
fstream
iostream
stdio
conio
iomanip
dos
stdlib.....
what else????
This is a discussion on a simple, silly yet big problem.... within the C++ Programming forums, part of the General Programming Boards category; I m getting the message " function seekg() needs a prototype " even though i have included: fstream iostream stdio ...
I m getting the message
" function seekg() needs a prototype "
even though i have included:
fstream
iostream
stdio
conio
iomanip
dos
stdlib.....
what else????
What's the code? seekg() is not a free function, it's a member of std::basic_istream.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
This is the code:
Code:/*Q 2. Assuming the class Applicant given below, write functions in C++ to perform the following : class Applicant { char A_Rno[10]; char A_Name[20]; int A_Score; }; (i) Write the objects of class to a binary file. (ii) Reads the objects of class from binary file and display them on screen. (iii) Searches for a particular A_Rno. (iv) Reads the file and lets the user make changes in data and invokes the function to display the values. (v) Just displays contents of the file. Note : Include all the required function’s prototypes in the public section of the class.*/ #include<fstream.h> #include<conio.h> #include<stdio.h> #include<process.h> #include<string.h> #include<iostream.h> #include<iomanip.h> #include<stdlib.h> #include<dos.h> int count=0; class applicant { char A_Rno[10]; char A_Name[20]; int A_Score; public: void getdata(); void showdata(); void search(); void mod(); }app; void applicant::getdata() { ofstream fout("app.dat",ios::binary); cout<<"\nEnter Rno :"; cin.getline(A_Rno,10); cout<<"\nEnter Name :"; cin.getline(A_Name,20); fout<<A_Rno<<A_Name; fout.close(); count++; } void applicant::showdata() { ifstream fin("app.dat",ios::binary); for(int i=0;i<count;i++) { fin.getline(A_Rno,10); fin.getline(A_Name,20); cout<<"\nRno : "; puts(A_Rno); cout<<"\nName : "; puts(A_Name); } fin.close(); } void applicant::search() { char rno[10]; cout<<"\nEnter the applicant's Rno to be searched.. "; cin.getline(rno,10); ifstream fin("app.dat",ios::binary); for(int i=0;i<count;i++) { fin.getline(A_Rno,10); fin.getline(A_Name,20); if(strcmp(A_Rno,rno)) { cout<<"\nApplicant found...\n"; cout<<"\nRno : "; puts(A_Rno); cout<<"\nName : "; puts(A_Name); } } fin.close(); } void applicant::mod() { int pos; char rno[10]; cout<<"\nEnter the applicant's Rno to be modified.. "; cin.getline(rno,10); fstream fin("app.dat",ios::binary); for(int i=0;i<count;i++) { fin.getline(A_Rno,10); fin.getline(A_Name,20); if(strcmp(A_Rno,rno)) pos=i; } int size=pos*sizeof(applicant); seekg(size,ios::beg); cout<<"\nEnter the new data"; cout<<"\nEnter Rno :"; cin.getline(A_Rno,10); cout<<"\nEnter Name :"; cin.getline(A_Name,20); fin<<A_Rno<<A_Name; fin.close(); } void main() { clrscr(); /*nt mrec=0,offset=0; fstream finout("student.dat",ios::binary); if(!student) { cout<<"\nFile could not be opened..."; getch(); exit(0); } */ begin: clrscr(); cout<<" MENU\n\n" <<" 1.Enter student data\n" <<" 2.Display Student data\n" <<" 3.Search for a record\n" <<" 4.Modify a record\n" <<" 5.Exit\n\n" <<" Enter your choice... "; int ch; cin>>ch; if(ch==1) { app.getdata(); /*mrec=count; offset=((mrec-1)*sizeof(applicant)); finout.seekp(offset,ios::beg); finout.write((char *)&app,sizeof(applicant));*/ goto begin; } if(ch==2) { app.showdata(); goto begin; } if(ch==3) { app.search(); goto begin; } if(ch==4) { app.mod(); goto begin; } exit(0); }
Should be fin.seekg(...).
Well, except that this doesn't work. The file isn't a fixed size binary record format where you can just overwrite the data. Or if it is, then you mustn't use the stream insertion operator for writing.
Last edited by CornedBee; 12-20-2007 at 06:18 AM.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
DONE...
had forgotten to use it as...
fin.seekg()
thnku
Ugh.
- use of goto very bad, use a while loop.
- void main, see the FAQ.
- every header file under the sun, half of them aren't necessary.
- choose between C OR C++, not some crazy mix.
- eliminate global variables.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
Use proper indenting. Don't go adding spacing to some lines but not others; keep indentation the same in the same block.
And use the same indentation everywhere. Like your functions use two spaces while your class uses a tab. Don't mix tabs and spaces - use one and stick with it everywhere.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^