Skip to main content
gamedev.net
🔒 Locked

understanding std::streambuf

Started by renqilin 1 reply 1.1k views
Original Post
renqilin
renqilin
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?
snk_kid
snk_kid
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
renqilin
renqilin
Thanks snk_kid, you've been a great help!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.