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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:40:37+00:00 2026-06-15T19:40:37+00:00

I am writing a huffman code in C++ and I am now taking data

  • 0

I am writing a huffman code in C++ and I am now taking data from the files and have encountered a snag. One the first line I have a string of characters that I want to take as a string, which I didn’t find hard at all to do. But then I have to take the next x amount of lines of numbers and take them as unsigned chars so I can use them.

What would I type in if I wanted to extract this form a file?

ILaILbILrILcLd (want to take as a string)

3 (the 3 is the number of #s below it)

89 (want to take these 3 out as unsigned chars

207

88

  • 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-15T19:40:38+00:00Added an answer on June 15, 2026 at 7:40 pm

    As Nike tells us, just do it:

    // read the line:
    std::string line1; 
    std::getline(infile, line1);
    
    // read the int:
    int num;
    infile >> num;
    // probably want to sanity check `num` here
    
    // define a place to store the chars
    std::vector<char> chars;
    
    // read the chars.
    for (i=0; i<num; i++) {
        unsigned int temp;
        infile >> temp;
        chars.push_back(static_cast<unsigned char>(temp));
    }
    

    It probably won’t accomplish much under the circumstances, but right after the definition of chars, you could add: chars.reserve(num); to avoid reallocation of the vectors memory.

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

Sidebar

Related Questions

Writing a file utility to strip out all non-ASCII characters from files. I have
I am writing a huffman implementation in Python as a learning exercise. I have
I have the following string that I would like to Huffman-encode and store efficiently
Writing an iPhone app, and I'm getting my data from a REST API that
Writing an iPhone app in Objective-C, I have a date in string form (in
Writing a lexer of .java source files in Java. I have a stream of
Writing some classes for a Framework extension, and I have the following code: public
Writing my first JQTouch app. When I go from #login to #home , a
Writing Classic ASP code in JScript has a lot going for it: more humane
Writing htaccess that allows me to remove index.php from the URL can confuse search

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.