Questions tagged [streambuf]

std::streambuf is the stream buffer type used by C++ iostreams.

C++ iostreams use a stream buffer to do any buffering of characters, manage the stream position and transport characters to/from an external device such as a file.

Use this tag for questions about std::streambuf, the wide-character equivalent std::wstreambuf, or the class template std::basic_streambuf. The tag might also be relevant.

141 questions
0
votes
3 answers

Query regarding overflow function of streambuf

Going thorugh overflow function documentation. I found overflow has following as return values. Return Value: A value different than EOF (or traits::eof() for other traits) signals success. If the function fails, either EOF (or traits::eof() for…
user258367
  • 2,917
  • 2
  • 16
  • 17
0
votes
1 answer

Customize streambuffer for C++ ostream

I am implementing my own streambuffer for output stream. Basically it is a vector-like streambuffer in which everytime the overflow function simply reallocates the buffer to two times larger. The sync function will write all data out to the device…
Jes
  • 2,132
  • 1
  • 18
  • 33
0
votes
0 answers

Reading from boost serial_port reads incorrect data every few readings

I'm placing a string in my stream buffer of the form of "000.3\r\n 000.3\r\n ...". Every few readings I catch a ".3\r\n 000.3\r\n ... Since, I'm only reading from the buffer once per frame those sudden jumps in value become noticeable when drawing…
ZeroPhase
  • 611
  • 3
  • 18
0
votes
1 answer

Custom streambuffer in std::ofstream

I know that in std::ostream, I can use a custom streambuf through either stating so in the constructor: std::ofstream temp; temp.open("file.txt", std::ios_base::in); std::ostream example(temp.rdbuf()); as well as by setting it afterwards (same…
user4912670
0
votes
2 answers

How to copy streambuf to unsigned char array?

how can I copy data in streambuf to a unsigned char array? The code below have compiler errors: boost::asio::streambuf buf; std::ostream os(&buf); boost::archive::binary_oarchive oa(os); oa << m_data; // allocate space for the buffer unsigned char*…
venusisle
  • 113
  • 2
  • 10
0
votes
1 answer

How do I build a filtered_streambuf based on basic_streambuf?

I have a project that requires me to insert a filter into a stream so that outgoing data will be modified according to the filter. After some research, it seems that what I want to do is create a filtered_streambuf like this: template
swestrup
  • 3,878
  • 3
  • 19
  • 29
0
votes
1 answer

How to return streambuf pointer

I have wrote my own input streambuf, which should work with gzipped files. Here is its interface: class gzstreambuf : public std::streambuf { static const int bufferSize = 8192; public: gzstreambuf(); ~gzstreambuf(); int is_open() {…
Vardan Hovhannisyan
  • 1,039
  • 3
  • 14
  • 36
0
votes
2 answers

std::stringstream buffer manipulation

I am putting some data into a stream buf obtained from stringstream std::stringstream data; auto buf = data.rdbuf(); buf->sputn(XXX); What I want is to be able to put some dummy data into this buffer and then at a later time, once I have the…
Arun
  • 2,808
  • 3
  • 26
  • 39
0
votes
1 answer

preload cin with a string of commands

I'm testing functions that require several console commands before they can execute. Instead of having to type those commands every single time I want to test the functionality of a particular method, I want to be able to just paste a line or two of…
user2514676
  • 317
  • 2
  • 5
  • 15
0
votes
3 answers

Why don't inherit from ifstream

I want to create a custom input file stream which automatically strips comments and other garbage data. I came up with the following solution: class FileReader : public std::ifstream { public: explicit FileReader(const char* fName) { open(fName);…
ifnull
  • 219
  • 1
  • 5
0
votes
1 answer

Passing from ostringstream to istringstream and to file

I desperately try to write in a ostringstream and then transfert the datas in the istringstream of an other object or in a file. std::ostringstream oss; oss << "Hello World"; For the first purpose, I try this…
fcaillaud
  • 31
  • 6
0
votes
1 answer

How does the buffer know how many characters to transfer from the external file during a flush operation?

Say I have an input operation: file >> x; If the internal buffer of file is empty underflow() will be called to import characters from the external device to the internal buffer of file. It is implementation-defined if the buffer will be partially…
0x499602D2
  • 87,005
  • 36
  • 149
  • 233
0
votes
1 answer

Implementation-defined synchronization of file streams - Why?

What was the rationale behind making synchronization of input file streams implementation-specific. Doesn't it seem obvious that the stream will fill its buffer (partially or wholly) with content from the external device? It says in Standard C++…
0x499602D2
  • 87,005
  • 36
  • 149
  • 233
0
votes
1 answer

Limit std::filebuf to file inside (archive) file

I am currently implementing a custom std::filebuf which reads files from uncompressed .zip archives. For each file in the archive I have the offset into the archive file and the size. Now I want to limit the filebuf to the interval [offset,…
Marius
  • 2,154
  • 13
  • 17
0
votes
0 answers

What the biggest size of output that std::codecvt::unshift() can need?

I am working on a custom file streambuf. Now, I want to flush on seek like fstream does. At this point I want to know how big the array for output of std::codecvt::unshift() should be? It seems to me that the size returned by…
wilx
  • 16,767
  • 5
  • 53
  • 109
1 2 3
9
10