Thread: Doubt in writing in binary file.

  1. #1
    Registered User
    Join Date
    Oct 2011
    Location
    India
    Posts
    53

    Doubt in writing in binary file.

    Hi folks, I had created a class for student. This is the class.
    Code:
    class student
    {
      int rollno,marks;
      char name[20];
     
     
     public:
        void show();
        void get();
        int filecreate(const string &,fstream &);
        int fileopen(const string &,fstream &);
        static int add(const student &,fstream &);
        static int read(const student &,fstream &,int);
        static int update(const student &,fstream &,int);
        int showall(fstream &);
        int view(fstream &,int );
        int adddummy(fstream &);
    };
    This is my add method to write a record in the binary file.
    Code:
    int student::add(const student &s,fstream &fp)
    {
            fp.seekp(0, ios::end);
            if(fp.write((char*)&s,sizeof s))
                return 1;
            return 0;
    }
    If i write the values of the object s, What are the values written to the file. Is it only rollno, marks and name (Data members only ?). Now i want to add a member for fstream. after adding the member, if i write the file, what data will write into the file (will the fstream values also write to file?)

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

  3. #3
    Registered User
    Join Date
    Oct 2011
    Location
    India
    Posts
    53
    Quote Originally Posted by Salem View Post
    Yes. Mr. salem !!! I have to finish my work very soon ! this also very slow to me ! so only i post the question in many forums.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Good for you - just so we all know, you can now sink to the bottom of the pile for selfishness.
    Choose your forum carefully
    Don't flag your question as "Urgent", even if it is for you
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. writing binary file
    By dtow1 in forum C Programming
    Replies: 5
    Last Post: 09-22-2011, 11:38 PM
  2. writing to a binary file
    By Inver28 in forum C Programming
    Replies: 4
    Last Post: 03-02-2008, 02:36 AM
  3. Writing to a Binary File
    By EvilBaby in forum C Programming
    Replies: 4
    Last Post: 04-12-2004, 05:15 AM
  4. Writing to a Binary File
    By Lah in forum C Programming
    Replies: 1
    Last Post: 10-27-2003, 01:41 AM
  5. Writing to a binary file
    By nz_cutechick in forum C++ Programming
    Replies: 5
    Last Post: 08-15-2002, 06:46 AM

Tags for this Thread