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.

152 questions
0
votes
1 answer

Sanity check: Does returning !EOF from streambuf-derived class' overflow function make sense?

I can find surprisingly little useful information about how an overridden std::streambuf::overflow function should look like to simply get each character that's written to the stream. So I asked ChatGPT for some pointers. It keeps coming back to…
Niko O
  • 406
  • 3
  • 15
0
votes
0 answers

Move Assignment Operator for a Custom Filtering Streambuf Class

I have written a "filtering streambuf" class (FilterStreambuf below). Only stream output is considered. The end goal is a std::ostream object which filters, writes to a std::ofstream, and has a move assignment operator. My problem and question is…
Tyson Hilmer
  • 741
  • 7
  • 25
0
votes
0 answers

SIGSEGV fault triggered by streambuf when used in multithread environment

I implement a output buffer LogStreamBuf derived from std::streambuf, It is used in multithread environment with lots of cout, SEGV error occurred when a large amount of output in a short period of time, the bt likes below, the param __n is invalid…
jackxie
  • 33
  • 1
  • 10
0
votes
0 answers

What does the "deprecated in C++98" indicate?

The quotation below is seen at cppreference: std::strstreambuf Defined in header class strstreambuf : public std::basic_streambuf (deprecated in C++98) What does the (deprecated in C++98) indicate? Does it mean that the…
John
  • 2,963
  • 11
  • 33
0
votes
1 answer

Writing a custom input manipulator

I need to make a custom istream manipulator that reads 5 characters from input, then skip 5 characters from input, and does it to the end of the string. Example: string line; cin >> skipchar >> line; This is that I did, but it doesn't work for some…
nameses
  • 3
  • 2
0
votes
1 answer

Where can I find a reference to the function write?

I have the following code for the definition of a streambuf class. I have to adapt it to my needs. Before that, I have to understand how the code actually works. Can anyone tell me where I can find a reference to the write function in flushBuffer. …
f ckx
  • 49
  • 1
  • 6
0
votes
1 answer

DPDK: compilation error while freeing MBUF

I am trying a simple MBUF create from an allocated pool and freeing the MBUF, however running into the following compilation issues.. If I comment out the mbuf_free, the program compiles fine.. Any pointers please ? Code : m =…
Jimmy
  • 51
  • 2
  • 9
0
votes
1 answer

Fail while redirect a std::ofstream to std::cout

I want to redirect std to a file. To do this, I wrote a class Foo, where I connect / disconnect the buffer in the writeToFilEnabled. However, there is Segmentation fault. How is it correct? #include #include class Foo…
0
votes
2 answers

How to prevent `std::cin` or `\n` from flushing the buffer of `std::cout`?

Let's imagine my program needs input from the user at different times. I want this input to prevent flushing the cout buffer. Can I set cin and cout on different stream buffers? Example in question: a program that reads two numbers in a line, n1 n2,…
Giogre
  • 1,444
  • 7
  • 19
0
votes
1 answer

Why do is the content of a buffer deleted, when it reads an empty rdbuf?

Quick example (play with code): int main() { std::stringstream sstr; sstr << "hello\n"; sstr << "world\n"; std::stringstream sstr2; // sstr2 << "test\n"; if (sstr2.rdbuf()->in_avail() != 0) { sstr <<…
User12547645
  • 6,955
  • 3
  • 38
  • 69
0
votes
1 answer

How to create streambuf with array of unsigned char in C++

I want to create a std::istream object with a stream buffer object that can take raw byte data from array of unsigned char. I searched and found this Link However they create the stream buffer based on array char: struct membuf : std::streambuf { …
user5005768Himadree
  • 1,375
  • 3
  • 23
  • 61
0
votes
1 answer

Redirecting from standard output to custom stream during program execution

I have a function which redirects messages from the standard output to a log file. The problem is, the messages are only written into the log file after the end of the program. Is it possible to write to the log file when the program is running? So,…
0
votes
2 answers

print out ostringstream buffer

Here is a simple piece of code what should print a std::ostringstream buffer, which in turn has been obtained via rdbuf(). I expect that this buffer to be printed to std::cout either via istreambuf iterators or directly via << operator. Surprisingly…
Sergey
  • 11
  • 5
0
votes
0 answers

"Deleted Function Reference" while using std::istream constructor

I'm trying to create a memory stream object to write to a block of memory as if it's a file (using the convenient functionality provided by std::istream). The basic idea is to create a bunch of wrappers for the std::streambuf class. The issue seems…
0
votes
1 answer

in_avail() is not returning correct number of bytes available after a sgetn(..,..) call

I have a input file(35413 bytes) and I am opening it using std::ifstream object and getting pointer to its buffer in a std::streambuf pointer. I am trying get remaining bytes in the stream using in_avail() function after every read. Below is the…