Say I want to read the contents of a file using basic_filebuf . I have a type boost::uintmax_t whose size is 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 are read, others not. For example, suppose there are 9 bytes in file number 1-9 :
|1|2|3|4|5|6|7|8|9|
When I run the above code, only one element is returned in data , which contains 4 bytes from only 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 using basic_filebuf directly, although I know how to use filebuf .
source share