S
Steven T. Hatton
What is the best way to read data from a file into a fixed size array of
unsigned char? This is a file holding only a SHA1 digest. What I would
really like to do is initialize the ifstream with the buffer allocated to
hold the data, seekg(ios_base::end) and magically have the data appear in
the buffer. I believe something close to this can be done.
I might allocate the array:
const unsigned LENGTH = 256;
unsigned char b[LENGTH];
Then cast it to a std::streambuf
std::streambuf sb(b[LENGTH]);
But can I construct std::ifstream that uses that same memory to hold the
data from its file? How to I prevent reading past the end of my buffer, or
the end of the file data?
unsigned char? This is a file holding only a SHA1 digest. What I would
really like to do is initialize the ifstream with the buffer allocated to
hold the data, seekg(ios_base::end) and magically have the data appear in
the buffer. I believe something close to this can be done.
I might allocate the array:
const unsigned LENGTH = 256;
unsigned char b[LENGTH];
Then cast it to a std::streambuf
std::streambuf sb(b[LENGTH]);
But can I construct std::ifstream that uses that same memory to hold the
data from its file? How to I prevent reading past the end of my buffer, or
the end of the file data?