Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:30:20+00:00 2026-06-16T01:30:20+00:00

class Student { public: Student *prev; char S_Name[15]; char F_Name[15]; int Reg_Num; char Section;

  • 0
class Student 
{
public:
Student *prev;  
char S_Name[15];
char F_Name[15];
int Reg_Num;
char Section;
char MAoI[15];
float CGPA;
Student *next;
} 

I have the above class and I want to write the data to a binary file of the link list when I exit the program and again read it back and form a link list when the program is run.
I have tried but failed on several attempts !

The code for Entering data `Student * Add_Entry()
{
Student *temp=new Student();

char s_Name[15];
char f_Name[15];
int reg_Num;
char section;
char mAoI[15];
float cGPA;

cout <<"**********************Menu***************************\n ";
cout<<"\nEnter the Studets name \"";
cin>>s_Name;

cout<<"\nEnter Father`s name \"";
cin>>f_Name;

cout<<"\nEnter the Registration Number \"";
cin>>reg_Num;

cout<<"\nEnter the Section \"";
cin>>section;

cout<<"\nEnter the Major Area of Interest \"";
cin>>mAoI;

cout<<"\nEnter the Current CGPA \"";
cin>>cGPA;

strcpy_s(temp->S_Name,s_Name);
strcpy_s(temp->F_Name,f_Name);
temp->Reg_Num=reg_Num;
temp->Section=section;
strcpy_s(temp->MAoI,mAoI);
temp->CGPA=cGPA;
temp->next=NULL;
temp->prev=NULL;
return temp;

//temp=Create_node(s_Name,f_Name,reg_Num,section,mAoI,cGPA);    

}`

To read from file i use ` char *buffer;

    ifstream reader;
    reader.open("student.bin",ios::in | ios::binary);
    if(reader.is_open)
    {
        do
        {
            reader.read(buffer,ch);
            if(Header==NULL)
            {
                Header=(Student)*buffer;
                temporary=Header;
            }

            else
            {
                temporary->next=(Student)*buffer;
                temporary=temporary->next;
            }
        }while(buffer!=NULL);
    }

`

And to write I use ` temporary=Header;
//Backup Entries
ofstream writer;
writer.open(“student.bin”,ios::out | ios::binary);

                while(temporary!=NULL)
                {   
                    writer.write((char)* temporary,sizeof(temporary));
                    temporary=temporary->next;
                }

                writer.close();

`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:30:22+00:00Added an answer on June 16, 2026 at 1:30 am

    This line:

    Header=(Student)*buffer;
    

    Means: Take buffer, which is probably a pointer to char, and dereference it, to get a char. Then cast that char into a Student. The compiler has no idea how to convert a char into a Student.

    If instead you do this:

    Header= *((Student *)buffer);
    

    It will cast the pointer to a pointer of the right type, and then dereference it to give a struct, which can be copied.

    You do that all over the place.

    Also, when reading, you don’t fill in the “next” pointer for the final item, nor the “prev” pointer for any. Although the “next” pointer in the last saved item might be zero (assuming it was saved correctly), the prev pointers could point at anything. Best practice would be to initialise everything correctly.

    Also:

    if(reader.is_open)
    

    should be:

    if(reader.is_open())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have these models: public class Student { public int Id { get; set;
I have a Student object: public class Student { public int Id { get;
I have a class student: public class Student { public int StudentId{get;set;} public string
Suppose I have two classes: public class Student { public int Id {get; set;}
I have a Student class in my application as below: public class Student {
I have a simple class Student under namespace School. namespace XmlTestApp { public class
I have two student objects. class Student{ int physics; int english; int chemistry; }
I have class Student { public List<Degree> Degrees {get;set;} } class Degree { public
I have created a class student with three properties like this public class Student
I have the following piece of code: class Student { public: Student(){} void display()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.