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

  • Home
  • SEARCH
  • 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 5974481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:56:58+00:00 2026-05-22T20:56:58+00:00

This is a sample that represents my problem. The map will serialize perfectly fine

  • 0

This is a sample that represents my problem. The map will serialize perfectly fine unless finalTime is greater than 25. With boost unit testing I was given a std::exception input stream error. Also, this code works fine using polymorphic_text_archives. The error occurs while reading in the map.

#include <fstream>
#include <iostream>
#define BOOST_ALL_DYN_LINK
#define BOOST_PARAMETER_MAX_ARITY 8
#include <boost/serialization/export.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_binary_iarchive.hpp>
#include <boost/archive/polymorphic_binary_oarchive.hpp>
#include <boost/static_assert.hpp>
#include <boost/serialization/map.hpp>

using namespace boost;

class DoubleTest
{
public:
    DoubleTest(double d)
    {
        this->Double = d;
    }

    DoubleTest()
    {
        this->Double = 0;
    }

    void serialize(boost::archive::polymorphic_iarchive & ar, const unsigned int)
    {
        ar & this->Double;
    }

    void serialize(boost::archive::polymorphic_oarchive & ar, const unsigned int)
    {
        ar & this->Double;
    }

    double Double;
};

int main(int argc, char** argv)
{
    const std::string fileName = "test.out";
    std::map<float, DoubleTest*> mymap;

    const int initialValue = 0;
    const int initialTime = 0;

    // A "finalTime" of 25 works. "26" does not.
    const int finalTime = 26;
    int value = 10;

    // Put values into the map.
    for(int time = initialTime; time < finalTime; time += 1)
    {
        value++;
        mymap[time] = new DoubleTest(value);
    }

    // Write a binary archive out.
    std::ofstream ofs(fileName.c_str());
    boost::archive::polymorphic_binary_oarchive oa(ofs);
    oa << mymap;
    ofs.flush();
    ofs.close();

    // Create a new map to read the binary archive into.
    std::map<float, DoubleTest*> mymap2;

    // Read in the new binary archive.
    std::ifstream ifs(fileName.c_str());
    boost::archive::polymorphic_binary_iarchive ia(ifs);
    ia >> mymap2;
    ifs.close();

    // Loop through the values to make sure they are correct.
    std::map<float, DoubleTest*>::iterator it; 
    for(it = mymap2.begin(); it != mymap2.end(); ++it)
    {
        std::cout << "Key: " << it->first << " ";
        std::cout << "Value: " << it->second->Double << '\n';
    }

    int pause;
    std::cin >> pause;
}
  • 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-22T20:56:59+00:00Added an answer on May 22, 2026 at 8:56 pm

    You need to serialize to a binary file stream. Add the ios_base::binary to the stream constructors.

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

Sidebar

Related Questions

Im sure this will be a simple one but have a project that started
This simple code is not producing any sound on a couple of machines that
I have this simple regex, [\d]{1,5} that matches any integer between 0 and 99999.
I know that this is a simple question for PHP guys but I don't
I've got a reasonably simple query (this time) that I need ALL the results
I've got a very simple WPF UserControl that looks like this: namespace MyUserControl {
I've got a very simple WPF UserControl that looks like this: namespace WpfControlLibrary1 {
I've got a simple java class that looks something like this: public class Skin
Let's say I have a simple stored procedure that looks like this (note: this
This is a (hopefully) really simple question - I have been told recently that

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.