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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:53:49+00:00 2026-05-15T23:53:49+00:00

I’ve created a small tool which is used to process binary files. All the

  • 0

I’ve created a small tool which is used to process binary files. All the functions involved in reading the files and processing them are templated and are similar to this:

template <class T> void processFile( const char* fileName );

The template parameter T is used to determine the size of data which will be read and treated as one item. I dont know how to say it precisely, so a tiny example (note that these are binary data as seen with a hexeditor). File contents:

BEEF1234DEAD5678

With T being unsigned char, items are: BE EF 12 34 DE AD 56 78
With T being unsigned int, items are: BEAF1234 DEAD5678
With T being a double: BEAF1234DEAD5678

(Note that I assume here that unsigned char is 1 byte, unsigned int is 4 bytes and double is 8 bytes large.) The T is also used for STL containers, because I use them a lot (a vector, a map and a list are used in many of the functions involved in processing files). Everything works perfectly fine with built-in datatypes (char, int etc.).

Now what is my problem: I would like to be able to work with sizes different from 1,4,8. For example 16, 32 or even 6, 10, 14 etc. As far as I know, there are no built-in types of these sizes. How can I achieve this? My main concern is that I need the data in STL containers and use sort() for example. Will a POD structure work? Note that I’m using mainly C functions for reading (no streams here, but some memcpy and memcmp, fread etc.).

Sorry for not providing more code, I’m using my spare laptop now. But i believe more code should not be necessary. If so, I will provide it tomorrow.

  • 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-15T23:53:49+00:00Added an answer on May 15, 2026 at 11:53 pm

    If I understand your question correctly, the answer is yes: you should be able to specialize your template function with a suitable POD type. However you’ll need to define a member operator<() in order to be able to use std::sort().

    The following POD might be useful to you in the general case (it will certainly sort better than doubles):

    template <int N>
    struct MyFill{
      char contents[N];
      bool operator<(const MyFill<N>& other){
        for (int i=0; i<N; ++i){
          if (contents[i]!=other.contents[i]){
            return (contents[i]<other.contents[i]);
          }
        }
        return false;
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would do the following: if your Clock-View appears ->… May 16, 2026 at 9:54 am
  • Editorial Team
    Editorial Team added an answer Still not quit sure what you need but does this… May 16, 2026 at 9:54 am
  • Editorial Team
    Editorial Team added an answer In DDD, Repositories are definitely where ALL persistence-related stuff is… May 16, 2026 at 9:54 am

Trending Tags

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

Top Members

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.