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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:59:04+00:00 2026-05-31T18:59:04+00:00

I need to get the byte stream of an object in C++. I could

  • 0

I need to get the byte stream of an object in C++.
I could not find a way to do this without using serialization.

NodeEntry *one = new NodeEntry("mani", 34, 56.3);

ofstream rofs("result.ros", ios::binary);
rofs.write((char *)&one, sizeof(one));
rofs.close();

// now we read the file into object!!    
ifstream ifsr("result.ros", ios::binary);
NodeEntry *oner;
ifsr.read((char *)&oner, sizeof(oner));

Is there any other workaround? I don’t want to send this object through the network or store it on hard disk. I just want to get the byte stream of object one without actually creating the file.

In other word I need to create a byte stream of object one and store it somewhere (like in an ostream), then passing these bytes to another method and re-construct the object from these bytes.

I would appreciate if you give me a hint on this.

  • 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-31T18:59:05+00:00Added an answer on May 31, 2026 at 6:59 pm

    You do realize that you’re writing the address of one, right? Basically what you’ve written is the equivalent of:

    NodeEntry** doublePtr = &one;
    oner = *doublePtr;
    

    If you wanted to write the contents of the object, you’d pass one to write and sizeof(NodeEntry), but as Dvir Volk mentions, this won’t work right (or at least probably not how you want it to) with anything that contains a pointer.

    Anyway, I like Google’s Protocol Buffers for serializing objects. It’s a far more robust solution to your problem.

    Also, “byte stream” makes no sense… do you mean the raw memory of the object in bytes?

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

Sidebar

Related Questions

I need to get an image from a SQL Server as a byte[], and
I need get it independent if the network connection is active or not. I
Apologies if this is somewhere, but I'm struggling to find the details I need
Frequently we get image from server as byte stream, then we create Bitmap and
I need to get the serialized XML representation of an object as a string.
I need to download a Cab file from a Url into a stream. using
I need get position element in table. But function position() returns me to the
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I need get all items these have no categories int? categoryId = null; var
Well, I need get two values that represents the distance between two full dates-only

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.