Thread: a simple, silly yet big problem....

  1. #1
    Registered User
    Join Date
    Dec 2007
    Location
    Delhi, India
    Posts
    6

    Question a simple, silly yet big problem....

    I m getting the message

    " function seekg() needs a prototype "

    even though i have included:
    fstream
    iostream
    stdio
    conio
    iomanip
    dos
    stdlib.....

    what else????

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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

  3. #3
    Registered User
    Join Date
    Dec 2007
    Location
    Delhi, India
    Posts
    6
    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);
    }

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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 07: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

  5. #5
    Registered User
    Join Date
    Dec 2007
    Location
    Delhi, India
    Posts
    6
    DONE...

    had forgotten to use it as...

    fin.seekg()

  6. #6
    Registered User
    Join Date
    Dec 2007
    Location
    Delhi, India
    Posts
    6
    thnku

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  2. problem with A simple modeless messagebox
    By hanhao in forum C++ Programming
    Replies: 8
    Last Post: 07-05-2005, 11:18 PM
  3. best download site
    By gooddevil in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-20-2004, 10:36 PM
  4. Sreen Resolution Statistics?
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 04-26-2004, 02:33 PM
  5. Simple? winsock client - server problem
    By knutso in forum Windows Programming
    Replies: 2
    Last Post: 03-26-2003, 04:51 AM