understanding std::streambuf

Started by
1 comment, last by renqilin 19 years, 2 months ago
i'm in a puzzle about std::streambuf. 1. what is streambuf::putback? and when it excute? 2. for the member function streambuf::overflow(int_type c), in case of (c == char_traits::eof()), what should happen? is there anyone can help me?
Advertisement
Quote:Original post by renqilin
i'm in a puzzle about std::streambuf.

1. what is streambuf::putback? and when it excute?


well first off all its std::basic_streambuf, second there isn't a member function called "putback" how-ever there is a member function called "sputbackc" which pushes characters back into the input stream and its not virtual so its not mean't to be overridden, its envoked in streams.

Quote:Original post by renqilin
2. for the member function streambuf::overflow(int_type c), in case of (c == char_traits::eof()), what should happen?


Well in std::basic_streambuf its a virtual member function that does usually nothing but return traits::eof() its mean't to be overriden by sub-types of basic_streambuf.

Quote:Original post by renqilin
in case of (c == char_traits::eof()), what should happen?


it must transfer characters contained in the internal buffer to the external device and most likely return "my_char_traits::not_eof(c);" to indicate everything went okay. Now this depends on weather your doing buffered character transportation or not, if not you can just return "my_char_traits::not_eof(c)".

I recommend getting this book Standard C++ IOStreams and Locales: Advanced Programmer's Guide and Reference
Thanks snk_kid, you've been a great help!

This topic is closed to new replies.

Advertisement