Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is streambuf? How do I use it?

Tags:

c++

iostream

I'm trying to learn a bit more about how I/O streams work in C++, and I'm really confused at when to use what.

What exactly is a streambuf?
When do I use a streambuf, as compared to a string, an istream, or a vector? (I already know the last three, but not how streambuf compares to them, if it does at all.)

like image 235
user541686 Avatar asked Nov 14 '11 02:11

user541686


People also ask

What is the use of Streambuf in C++?

A stream buffer is an object in charge of performing the reading and writing operations of the stream object it is associated with: the stream delegates all such operations to its associated stream buffer object, which is an intermediary between the stream and its controlled input and output sequences.

What is an Ostream?

ostream is a general purpose output stream. cout and cerr are both examples of ostreams. ifstream is an input file stream. It is a special kind of an istream that reads in data from a data file. ofstream is an output file stream.

What is stream buffer?

Stream buffers, also known as riparian buffers, are vegetated areas on either side of a stream. or river. When functioning properly, buffers protect the waterbody from the impacts of human activity. Buffers can differ greatly, ranging from flat floodplains to steep gorges.

What is Filebuf C++?

Description. filebuf s specialize streambuf s to use a file as a source or sink of characters. Characters are consumed by doing writes to the file, and are produced by doing reads. When the file is seekable, a filebuf allows seeks. At least 4 characters of putback are guaranteed.


1 Answers

With the help of streambuf, we can work in an even lower level. It allows access to the underlying buffers.

Here are some good examples : Copy, load, redirect and tee using C++ streambufs and in reference to comparison, This might be helpful,

enter image description here

See this for more details : IOstream Library

like image 171
COD3BOY Avatar answered Oct 02 '22 00:10

COD3BOY