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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:04:53+00:00 2026-05-11T05:04:53+00:00

I have a small hierarchy of objects that I need to serialize and transmit

  • 0

I have a small hierarchy of objects that I need to serialize and transmit via a socket connection. I need to both serialize the object, then deserialize it based on what type it is. Is there an easy way to do this in C++ (as there is in Java)?

Just to be clear, I’m looking for methods on converting an object into an array of bytes, then back into an object. I can handle the socket transmission.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:04:53+00:00Added an answer on May 11, 2026 at 5:04 am

    Talking about serialization, the boost serialization API comes to my mind. As for transmitting the serialized data over the net, I’d either use Berkeley sockets or the asio library.

    If you want to serialize your objects to a byte array, you can use the boost serializer in the following way (taken from the tutorial site):

    #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_iarchive.hpp> class gps_position { private:     friend class boost::serialization::access;     template<class Archive>     void serialize(Archive & ar, const unsigned int version)     {         ar & degrees;         ar & minutes;         ar & seconds;     }     int degrees;     int minutes;     float seconds;  public:     gps_position(){};     gps_position(int d, int m, float s) :     degrees(d), minutes(m), seconds(s)     {} }; 

    Actual serialization is then pretty easy:

    #include <fstream> std::ofstream ofs("filename.dat", std::ios::binary);      // create class instance     const gps_position g(35, 59, 24.567f);      // save data to archive     {         boost::archive::binary_oarchive oa(ofs);         // write class instance to archive         oa << g;         // archive and stream closed when destructors are called     } 

    Deserialization works in an analogous manner.

    There are also mechanisms which let you handle serialization of pointers (complex data structures like tress etc are no problem), derived classes and you can choose between binary and text serialization. Besides all STL containers are supported out of the box.

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

Sidebar

Related Questions

I have a small hierarchy of classes that all implement a common interface. Each
I have small application that is uploading pictures to another website via webservice. My
I have a small class hierarchy that I'm having trouble implementing copyWithZone: for. I've
I have a not-so-small class under development (that it changes often) and I need
I have a small class hierarchy where I would like to have a child
I have small test app: Socket socket = new Socket(jeck.ru, 80); PrintWriter pw =
I have small web app that generate PDF files as a report. I'm trying
I have small class called 'Call' and I need to store these calls into
i have small function that running on condintion, if text box value is not
I have an object, RenderComponent , that has a property named Model that is

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.