i try to read parts of a binary file content into a string. Why a string? I need this for my message protocol (with protobuf).
The following works very well:
std::string* data = new std::string();
std::ifstream ifs("C:\\data.bin", std::ios::binary);
data->assign((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
But this is for reading the file from the beginning to end. I would like to read only parts at given position. For example begin at position byte 10:
std::string* data = new std::string();
std::ifstream ifs("C:\\data.bin", std::ios::binary);
ifs.seekg((10);
data->assign((std::istreambuf_iterator<char>(ifs)), ???????);
But how to adjust the end or the offset? I did not find any example. I know there are examples with ifstream.read() into buffers. I used the assign into string method in my whole program and would really love to find a way doing this with offset.
Can anyone help me? Thanks