c++ - Understanding the design of std::istream::read -


std::istream has prototype istream& read (char* s, streamsize n) actual number of bytes read should gotten calling istream::gcount(), validity of istream can known ios::good.

i discussing stream class' implementation trying write colleague of mine, saying might follow design; said instead of having user call gcount everytime, 1 have read's prototype istream& read (char* s, streamsize n, size_t &bytes_read) it'll on in single call , former clumsier. unable defend std's design choice. what's real rationale behind istream::read?

i assume it's because c++ doesn't typically force interface may not needed everyone. if require read accept parameter people don't care about, causes coding work (declaring int pass parameter). saves bytes read regardless of whether client cares or not (some clients may care read failed indicated eof/fail bits).

with separate method de-couple interface different pieces of information may or may not needed.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -