Is there anyway to read a known number of bytes, directly into an std::string, without creating a temporary buffer to do so?
eg currently I can do it by
boost::uint16_t len;
is.read((char*)&len, 2);
char *tmpStr = new char[len];
is.read(tmpStr, len);
std::string str(tmpStr, len);
delete[] tmpStr;
std::stringhas aresizefunction you could use, or a constructor that’ll do the same:This is untested, and I don’t know if strings are mandated to have contiguous storage.