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
3
votes
1 answer

Is std::stringstream::flush() supposed to do anything?

std::ostream's have a flush() method which: Writes uncommitted changes to the underlying output sequence. What does that mean for an std::stringstream? If I understand correctly, it means there's nothing to be done for such a stream. Is this…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
3
votes
1 answer

CRTP call child function in destructor of parent

I have two classes structured like so (simplified the code to show the problem more clearly): template class Stream : public std::basic_streambuf> { private: std::string pBuffer; //other…
Brandon
  • 22,723
  • 11
  • 93
  • 186
3
votes
3 answers

What are 'aliased' stream buffers?

What are 'aliased stream buffers`? I encountered the term in a comment on an answer of mine.
xtofl
  • 40,723
  • 12
  • 105
  • 192
3
votes
3 answers

Taking ownership of streambuf/stringbuf data

I'd like an interface for writing to an automatically resizing array. One way to do this is with a generic std::ostream *. Then consider if ostringstream is the target: void WritePNG(ostream *out, const uint8_t *pixels); void…
Yale Zhang
  • 1,447
  • 12
  • 30
3
votes
1 answer

Does `basic_streambuf` create its own get/put areas if you don't do it in a derived class implementation?

I've seen the instructions for creating custom streambufs many times: All you need to do is implement overflow, underflow, and pbackfail properly in a descendant of std::basic_streambuf and you can create a stream that formats data using it. Those…
Spencer
  • 1,924
  • 15
  • 27
3
votes
3 answers

How can I read from memory just like from a file using wistream?

In my previous question I asked how to read from a memory just as from a file. Because my whole file was in memory I wanted to read it similarly. I found answer to my question but actually I need to read lines as a wstring. With file I can do…
Mariusz Pawelski
  • 25,983
  • 11
  • 67
  • 80
3
votes
1 answer

How to create a C++ streambuf object from a C FILE*, sharing its buffer (and buffer state) with the FILE object pointed to?

How can I get a C++ streambuf object from a C FILE* so that it uses the FILE object’s buffer, avoiding both objects to manage separate buffers while pointing to the same underlying file. It looks like there is no standard way of doing that. Boost…
Guett31
  • 258
  • 2
  • 15
3
votes
2 answers

int_type not naming type frustration

I have a virtual method type int_type in code being adapted from here that is the only case where the code gives the compile error: ‘int_type’ does not name a type int_type ThreadLogStream::overflow(int_type v) ^. Debugging steps so far If I…
Graeme Rock
  • 601
  • 5
  • 21
3
votes
1 answer

boost.asio - set maximum read stream size

There's example HTTP Client at http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/example/http/client/async_client.cpp Please help me to change maximum buffer size like explained in following code (it's from examples downloaded with library,…
soulmare
  • 73
  • 1
  • 7
3
votes
2 answers

streambuf with boost::asio::async_write

Tell me how to use boost::asio::streambuf with boost::asio::async_write. I have a server application that connects to it one client. For each connection I create object tcp_connection. How do I properly create buffer for sending data if I need to…
vint
  • 161
  • 1
  • 2
  • 5
3
votes
1 answer

Boost streambuf to const char* with buffer_cast vs std::string vs ostringstream

I have a client/server application using boost::read_until with a boost::streambuf. I'm reading an XML message from a socket and want to parse this with tinyXML2 like so: XMLDocument doc; doc.parse(strPtr); // strPtr is const char* I need to…
frankhond
  • 427
  • 4
  • 15
3
votes
4 answers

Deriving streambuf or basic_ostringstream?

I want to derive a stringstream so that I can use the operator<< to construct a message which will then be thrown. The API would look like: error("some text") << " more text " << 42 << std::endl; This should do a throw "some text more text 42" So…
Giovanni Funchal
  • 8,934
  • 13
  • 61
  • 110
3
votes
2 answers

C++: Best text accumulator

Text gets accumulates piecemeal before being sent to client. Now we use own class that allocates memory for each piece as char massive. (Anyway, works like char[][] + std::list). Then we build the whole string, convert it into std::sting and…
Ben Usman
  • 7,969
  • 6
  • 46
  • 66
3
votes
1 answer

Implementing std::basic_streambuf subclass for manipulating input

I have a std::basic_streambuf subclass that causes all output to be written in uppercase, like this: class upper_streambuf : public std::streambuf { public: upper_streambuf(std::streambuf &real) : m_realBuffer(real) { …
dreamlax
  • 93,976
  • 29
  • 161
  • 209
3
votes
1 answer

Is it possible to make streams of non-POD types?

In C++, I need to make streams of objects which are of non-POD type using my own implementation of std::basic_streambuf. Is the standard library required to construct/destroy the objects when expected?
Hristo Venev
  • 972
  • 5
  • 17