You can put whatever you want at the end of the buffer as long as there is room for it. istream::read does not tell you how many bytes it reads; it either reads everything you requested, or changes the state of the stream to fail / eof.
If you want to handle a case where you may have fewer bytes than expected, use istream::readsome , it returns the number of bytes retrieved.
As the other answers mentioned, if you are dealing with strings, use functions that read strings, such as std::getline or extractors >> . istream::read for binary data - in this case std::streambuf usually more convenient to use.
source share