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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:04:29+00:00 2026-06-12T11:04:29+00:00

Java has a very simple way to serialize objects. couldn’t find something similar in

  • 0

Java has a very simple way to serialize objects. couldn’t find something similar in C++.
I found Boost Serialization, and a basic approach using ifstream and ofstream.

I have a Task class wich has a title, id, status and date/time. I want to implement a serialize function within the class to save that object in binary mode.
But I want to save multiple instances of the class on a single binary file. Let’s say, a Task array.

Would it be a good approach to implement a serialize method on the class? It will only serialize one at a time and It doesn’t looks well-done if I use ifstream/ofstream, as I’ll be opening and closing files a lot. Also every task will be saved on different files.

Boost’s serialization looked fine, but is best for me to avoid 3rd party dependencies if possible.

What would be the best way of accomplish this?

My class header:

#ifndef TASK_H
#define TASK_H

class Task {
    public:
        enum Status { COMPLETED, PENDIENT };
        Task(std::string text);
        ~Task();
        // SETTERS
        void setText(std::string text);
        void setStatus(Status status);
        // GETTERS
        const std::string getText() const;
        const bool getStatus() const;
        const int getID() const;
        const int getCount() const;
        const std::string getDate() const;
        const std::string getTime() const;
        // DATE
        const int getDay() const;
        const int getMonth() const;
        const int getYear() const;
        // TIME
        const int getSecond() const;
        const int getMinute() const;
        const int getHour() const;
        // UTILS
        //serialize
        const void printFormatted() const;
        // OVERLOAD
        bool operator==( const Task &text2 ) const;
    private:
        void setID();
        static int sCount;
        int id;
        std::string text;
        Status status;
        tm *timestamp;
};

#endif
  • 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-12T11:04:30+00:00Added an answer on June 12, 2026 at 11:04 am

    If you only have a single, very simple class to serialise out, it’s not that hard to implement a serialisation function that writes out the handful of members that you need to save. You don’t give a code example that shows your class, but with a handful of members it should be comparatively easy as long as there are no pointers involved. If you write out the number of objects serialised followed by the data contained therein, that would probably be good enough for your purposes.

    If you want to implement the serialisation yourself, I would have an external function (possibly a friend of your class) handle the serialisation of the Task array rather than trying to put the array serialisation into your class. What you can do is add a serialiseObject() function to your class that serialises a single object, then call it repeatedly from the array serialisation function. That’s a much cleaner design than having the array serialisation also bolted onto the class itself.

    Once you get into serialising C++ object that are a little more complex, especially ones containing references and pointers, serialisation very quickly becomes a hard problem and you really, really want to use an existing, third-party mechanism that has been well tested.

    That said, as someone who does C++ development for a living, I consider a dependency on boost as normal, not a third party library I would want to avoid. Boost gives you so much additional functionality that I consider it part of “my standard library”.

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

Sidebar

Related Questions

Say I have a very simple java object that only has some getXXX and
My Java application has got a package structure similar to this: src/com/name/app src/com/name/app/do src/com/name/utils/db
What is the most efficient way to split a string by a very simple
I decided to implement a very simple program recursively, to see how well Java
I have a bunch of very simple functions. Each function has one input and
I'm sure my code is correct and this is just something very simple giving
There is a simple application that works in Windows. It has very simple interface:
I have a very simple Player class in java that uses some strategies object
I have a very simple batch file that lauches a Java app (Saxon) with
I want to write a very simple implementation of an onion router in Java

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.