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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:17:22+00:00 2026-05-10T22:17:22+00:00

basically, I’ve got my Huffman table as std::map<std::string, char> ciMap; Where string is the

  • 0

basically, I’ve got my Huffman table as

std::map<std::string, char> ciMap; 

Where string is the bit pattern and char is the value represented by said pattern. The problem is how do I store that as a header of my compressed file so I can build again the same map when I want to decode it?

Trying to store it as binary:

size_t mapLen = ciMap.size(); outFile.write(reinterpret_cast<char*>(&mapLen), sizeof(size_t)); outFile.write(reinterpret_cast<char*>(&ciMap), sizeof(ciMap)); 

And later building with:

inFile.read(reinterpret_cast<char*>(&mapLen), sizeof(size_t)); inFile.read(reinterpret_cast<char*>(&ciMap), sizeof(mapLen)); 

Doesn’t work, I get string initilization error… something to do with NULL. Any suggestions? If you have better way of storing the bits and values I’d like to hear.

  • 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. 2026-05-10T22:17:23+00:00Added an answer on May 10, 2026 at 10:17 pm

    You can do it yourself, or you can do it with boost: http://www.boost.org/doc/libs/1_37_0/libs/serialization/doc/index.html. What you currently try is just view the map as a plain old datatype, which essentially means it’s a C datatype. But it isn’t, so it fails to save/load. boost serialization does it correctly. Have a look at it. If you don’t want to use it, you can do something like this:

    typedef std::map<std::string, char> my_map; my_map ciMap;  // saving std::ofstream stream('file.txt'); for(my_map::const_iterator it = ciMap.begin(); it != ciMap.end(); ++it) {     stream << it->first << ' ' << it->second << std::endl; }  // loading char c; std::string bits; std::ifstream stream('file.txt'); while(stream >> bits >> c)     ciMap.insert(std::make_pair(bits, c)); 

    Note that the above needs some changes if the characters stored could be whitespace characters too. Because of that, it’s probably the best to first convert to an int before writing out, and then reading as an int when loading. Actually, i recommend boost serialization, and boost iostreams (http://www.boost.org/doc/libs/1_37_0/libs/iostreams/doc/index.html), which includes a compression stream that transparently can compress your data too.

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

Sidebar

Ask A Question

Stats

  • Questions 98k
  • Answers 98k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I got a wee-bit curious -- some older discusions on… May 11, 2026 at 7:32 pm
  • Editorial Team
    Editorial Team added an answer You can use PathGetCharType function, PathCleanupSpec function or the following… May 11, 2026 at 7:32 pm
  • Editorial Team
    Editorial Team added an answer Short answer: Going to extremes to avoid Hard Coding and… May 11, 2026 at 7:32 pm

Related Questions

Basically, I would like a brief explanation of how I can access a SQL
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I
Basically, I'm trying to create an object of unique objects, a set. I had
Basically, I have a class with 2 methods: one to serialize an object into
Basically, I'm trying to selectively copy a table from one database to another. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.