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 7090609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:04:33+00:00 2026-05-28T08:04:33+00:00

I have these C++ headers #include <iostream> #include istruttore.h #define max 30 using namespace

  • 0

I have these C++ headers

#include <iostream>
#include "istruttore.h"
#define max 30

using namespace std;
//==============================================================================
class corso
{
  friend ostream& operator << (ostream& out, const corso& corsoapp);
  friend istream& operator >> (istream& in, corso& corso);

  public:
       int getid_corso();
       char* getnomecorso();
       double getcosto();
       char* getdurata(); 
       int getistruttore_id();
       char* getistruttore_name();
       char* getistruttore_surname();
       void setid_corso(int course);
       void setnomecorso(char namecourse[]);
       void setcosto (double pay);
       void setdurata(char duration[]); 
       void set_istruttore(char name[], char surname[], int id, int id_corso);
       corso();
       ~corso();
       istruttore* ist;
   private:
       int id_corso;
       char nomecorso[max];
       double costo;
       char durata[max];
    };



#include <iostream>

#define max 30

using namespace std;
//==============================================================================
class istruttore {
friend ostream& operator <<(ostream& out, const istruttore& istruttoreapp);
friend istream& operator >>(istream& in, istruttore& istruttore);

public:
 int getid_istruttore();
 char* getnome();
 char* getcognome();
 int getid_corso();
 void setid_istruttore(int idistruttore);
 void setnome(char name[]);
 void setcognome(char surname[]);
 void setid_corso(int idcorso);
 istruttore();
 ~istruttore();
protected:
 int id_istruttore;
 char nome[max];
 char cognome[max];
 int id_corso;
  };

I have implemented all methods for both headers. I want to write a binary file in this way:

fcliente.write(reinterpret_cast<const char*>(&tmpcorso),sizeof(tmpcorso));

where tempcorso is an object of type corso. Writing is ok, but reading isn’t ok.
I try to read the same binary file with this code

fcorso.read(reinterpret_cast<char*>(&tmpcorso),sizeof(tmpcorso))

but when I look at the value of istruttore in tmpcorso the value isn’t ok. How do I fix it?

  • 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-05-28T08:04:34+00:00Added an answer on May 28, 2026 at 8:04 am

    Your problem is the pointer

       istruttore* ist;
    

    If you write it out and immediately read it in again during the same run of the program, the pointed-to object might still be there.

    If you save the file and read it in sometimes later, it is highly likely that the istruttore object is somewhere else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

id.cpp #include stdafx.h #include <iostream> using namespace std; class A { public: static int
I have the following code which works as expected: #include <iostream> using namespace std;
I have a Mammal.h file that reads: #ifndef MAMMAL_H #define MAMMAL_H class Mammal {
Suppose that I have those three files: a.h //a.h header #include <stdio.h> int int_variable;
I have to include many header files, which are in different sub-directories. Is there
I have headers in <h1> through <h6> tags. Is there a way that I
I have these two pieces of code, wich one is more readable? foreach decimal
I have these 3 tables + data: items : itemId, itemName data: 1, my
I have these 2 vectors: alpha = 1 1 1 1 1 1 1
I have these container objects (let's call them Container) in a list. Each of

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.