0

For context, I serialized a FlatBuffers object, saved it to a binary file data.bin, and now want to read it back.

Following the example here https://stackoverflow.com/a/54446430/3927314, I have

std::ifstream infile("data.bin", std::ios_base::binary);
std::vector<char> buffer(
    std::istreambuf_iterator<char>(infile),
    std::istreambuf_iterator<char>()
    );
std::cout << buffer.size() << std::endl; // error

On the last line, why do I get this error when compiling? I was confused because I thought size() is a member function that can be called on all std::vector objects.

error: request for member 'size' in 'buffer', which is of non-class type 'std::vector<char>(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> > (*)())'

kgf3JfUtW
  • 13,702
  • 10
  • 57
  • 80

0 Answers0