jeudi 28 juillet 2016

How to read a fix-byte data from a c++ std::istream

How to read a fix-byte data from a std::istream without doing any extraction? For example, I have a variable sz of type size_t and I would like to read sizeof(size_t) bytes from the istream.

void foo(std::istream& is) {
  if(is.rdbuf()->in_avail() < sizeof(size_t)) return;
  // how to read to sz from istream is without extraction (advancing pointers)
  size_t sz;
}

Aucun commentaire:

Enregistrer un commentaire