On Apr 6, 6:32*pm, Sam <s...@email-scan.com> wrote:
> Immortal Nephi writes:
> > * *cout object has stream buffer. *It is derived from ostream object.
> > How many characters do stream buffer hold?
>
> Implementation defined.
>
> > * * * * * * * * * * * * * * * * * * * * * * *Or…do ostream object
> > resize to increase stream buffer’s memory size if characters are full?
>
> Implementation defined. Most implementations use a fixed default buffer
> size. Once the buffer is full, the buffer's contents are flushed to the
> underlying system file.
>
> > * *Is there a way to reread stream buffer and output to the screen
> > second time?
>
> You could use rdbuf() to obtain a pointer to the stream buffer, and use its
> method to get the current head or tail pointer.
>
> However, that would be of very little use. Since the implementation may use
> whatever buffer flushing strategy it feels like using, you have no
> guarantees whatsoever what you'll get. You may find yourself with a buffer
> that contains everything that was written to the stream, since its
> instantiation. Or, you may find yourself with an empty buffer, because its
> contents have just been flushed, completely.
>
>
>
> > For example:
>
> > * *cout << “Hello World!”;
> > * *cout // ?? reread stream buffer
>
> > * *“Hello World!” is inserted into stream buffer. *I did not add endl
> > manipulator because I did not want to flush stream buffer. *Can I copy
>
> This is true, however std::endl merely guarantees that the stream gets
> flushed, if the stream is set to flush at endl. Your implementation is free
> to flush the stream buffer at other times, so you may find that, for
> whatever reason, your stream buffer chose to flush itself right after the
> exclamation mark got inserted.
>
> This may not be true any more, but at least in the past glibc set cerr by
> default to be completely unbuffered. Every operator<<(), essentially,
> did a flush().
Are you saying? If endl manipulator is omitted from cerr, then
operator<<() automatically flush stream buffer because cerr is
unbuffered. Correct?
> > cout’s stream buffer to another stream buffer before I flush cout’s
> > stream buffer?
> > * *Maybe I want cout object and fstream object to share one stream
> > buffer. *Stream buffer is sent to the console screen while it is
> > written to the disk at the same time.
>
> The only portable way to do this is to write your content twice, yourself,
> once to cout, and a second time to another stream.
>
> Or, you can always write your content to a std:
stringstream, then retrieve
> everything as a single blob using str(), then write the resulting string to
> cout and the other stream.
If I want to create my own ostream object, I should use streambuf
object. Right? Is streambuf the same as filbuf, but the difference
is that streambuf sends to the console screen and filbuf sends to the
file.
What is the difference between sstream object and strstream object?
If I use the prefix basic_ object, can I choose any type such as int
and float instead of char and wchar_t?