Jump to content

How can I split a binary file data in an array?


Dragonfighter
 Share

Recommended Posts

#include <iostream>
#include <fstream>
#include <string>

int main () {
  std::ifstream is ("image.png", std::ifstream::binary);
  unsigned char buffer_array[4][4];
  if (is) {

    is.seekg (0, is.end);
    int length = is.tellg();
    is.seekg (0, is.beg);

    char * buffer = new char [length];
    is.read (buffer,length);
    //Here I get the error
    unsigned char * buffer_str=buffer;
    for (int count1=0; count1<4; count1=count1+1)
        {
            for (int count2=0; count2<4; count2=count2+1)
            {
                //Here I get the others two errors
                buffer_array[count1][count2]=buffer_str.substr(0, 2);
                buffer_str.erase(0, 2)
                };
                };

  return 0;
};
};

My goal is to split the binary buffer of the image.png in an array, I tried using string modifiers but I get two errors: request for member 'erase' in 'buffer_str', which is of non-class type 'unsigned char*' thats what I get when build.

 

 

Edited by Dragonfighter
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...