Sign in to follow this  
renqilin

understanding std::streambuf

Recommended Posts

renqilin    194
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?

Share this post


Link to post
Share on other sites
snk_kid    1312
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this