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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:48:09+00:00 2026-05-27T11:48:09+00:00

How is data stored when read in using fstream class ? An example will

  • 0

How is data stored when read in using fstream class? An example will clarify my question:

    char * memBlock = NULL;
    fileSize = file.tellg();
    memBlock = **new** char[fileSize];
    file.seekg(0, ios::beg);
    file.read(memBlock, fileSize);
    file.close();

    if(memBlock)
    return memBlock;

The context is that I am reading a raw image that has been recorded in hex so that

  • the values representing the pixels are either 00 or ff (black or white, 1 or 0)
  • and are arranged in columns and rows.

When reading the file in memory, are the values in the memblock array stored as ff and 00 or are they converted into 1 and 0 automatically by ASCII or something?

  • 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-27T11:48:09+00:00Added an answer on May 27, 2026 at 11:48 am

    When the data is stored as hex

    00FF00FF
    

    and you read it using file.read as shown in your code,
    then it is stored as that, which means that

    memcmp(memblock, "00FF00FF", 8) == 0
    

    will evaluate to true.

    EDIT

    You have to make the conversion yourself. One way would be

    int ConvertToColor(const char *colorBuffer, size_t size)
    {
        int color = -1;
        if(size >= 2)
        {
            char colorCode[3] = { colorBuffer[0], colorBuffer[1], 0 };
            long longColor = strtol(colorCode, NULL, 16);
            if(longColor != LONG_MAX && longColor != LONG_MIN)            
                color = (int)longColor;
    
        } 
        return color;   
    }
    
    std::vector<int> ConvertToColors(const char *memBlock, size_t size)
    {
        std::vector<int> colors;
        for(size_t i = 0; i < size; i += 2)
        {
            int color = ConvertToColor(memBlock + i, size - i);
            if(color < 0)
                throw std::exception("Unable to convert color.");
            colors.push_back(color ? 1 : 0);
        }
        return colors;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My iPhone app will have read-only system data AND read/write user data (stored either
I am using this code to read data from Oracle Database. That data stored
I am trying to read in data stored in a custom binary file generated
I have a C++ program that will read in data from a binary file
I read somewhere that config data is stored under user account->Local Settings->Application data, but
Suppose I have any data stored in bytes. For example: 0110001100010101100101110101101 How can I
I want to do following: Make Oracle stored procedure for read all data from
this website gives a great example of how to get all the data stored
I am using a TStream to read binary data (thanks to this post: How
I'm reading a file in C++ using streams, specifically, fstream, not ifstream. blah blah

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.