Say I want to read the contents of a file using basic_filebuf
. I have a type called boost::uintmax_t
which has a size of 8 bytes
. I am trying to write the following:
typedef basic_filebuf<uintmax_t> file;
typedef istreambuf_iterator<uintmax_t> ifile;
file f;
vector<uintmax_t> data, buf(2);
f.open("test.txt", std::ios::in | std::ios::binary);
f.pubsetbuf(&buf[0], 1024);
ifile start(&f), end;
while(start != end)
{
data.push_back(*start);
start++;
}
The problem is that some of the bytes
get read, others don't. For example, lets say there are 9 bytes
in the file numbered 1-9
:
|1|2|3|4|5|6|7|8|9|
When I run the above code, only one element is pushed back into data
, which contains 4 bytes
only from the original data in f
:
[0|0|0|0|4|3|2|1] --> only element in [data]
What am I doing wrong? This is my first time to use basic_filebuf
directly, though I know how to use filebuf
.