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
1
vote
0 answers

Overwrite last line outputted to std::cout in a stream-like fashion

Hi, Here is what I am trying to achieve. I would like to have a stream, defaulting to outputting to std::cout but that could work with std::cerr too, that allows overwriting the last outputted line. I am aware this will not work with seekp because…
ibizaman
  • 3,053
  • 1
  • 23
  • 34
1
vote
2 answers

Deriving from `boost::asio::streambuf`

I'm trying to create my class which is simply public-derived from boost::asio::streambuf with some methods added: class my_super_streambuf : public boost::asio::streambuf { public: void my_super_method(); }; But when I simply replace…
vladon
  • 8,158
  • 2
  • 47
  • 91
1
vote
1 answer

C++ how to flush std:stringbuf?

I need to put the standard output of a process (binary data) to a string buffer and consume it in another thread. Here is the producer: while (ReadFile(ffmpeg_OUT_Rd, cbBuffer, sizeof(cbBuffer), &byteRead, NULL)){ tByte += byteRead; //total…
Alvin
  • 149
  • 1
  • 10
1
vote
1 answer

Creating a substreambuf to read from an existing istream

I'm attempting to create a custom std::streambuf which acts as a sub-stream to a parent stream. This is an adaptation of the implementation outlined in this SO thread answer. In this example below I am attempting to simply read the first 5…
Colin Basnett
  • 4,052
  • 2
  • 30
  • 49
1
vote
0 answers

(C++) ifstream::eof() when ifstream created from boost::asio::steambuf

It's my bad or a bug in boost::asio::streambuf implementation? In down case i create instance of boost::asio::streambuf, then instance of std::istream and write 3 int to streambuf. Then i need read int's from streambuf while it contain a data. I'm…
1
vote
1 answer

How do I declare a custom char_traits<> for my own type?

I want to make a custom char_traits class for my own type. I have declared all the functions, but I am having some confusion regarding vague semantics given in the standard. What are fpos_type, off_type and state_type expected to do? Where are they…
Anurag Kalia
  • 4,668
  • 4
  • 21
  • 28
1
vote
0 answers

Custom strbuf doesn't put anything in the file

I am trying to make a custom strbuf that takes in 32-byte characters and puts them in another ostream object in bytes. Following is the code for it: I personally suspect the way I have linked it in main.cpp though I can't pinpoint the error in it.…
Anurag Kalia
  • 4,668
  • 4
  • 21
  • 28
1
vote
1 answer

Wrapping libcurl with std::streambuf for uploads?

I've implemented the read half of the std::streambuf API (i.e., underflow() and xsgetn()) around libcurl so that an ordinary istream can have such a streambuf plugged into it and retrieve the contents from HTTP or FTP servers. It works great. Now…
Paul J. Lucas
  • 6,895
  • 6
  • 44
  • 88
1
vote
1 answer

Tricks to pass from a ostringstream to a istringstream

I try to make a module of compression/decompression and then use istringstream for compression and ostringstream for decompression. My problem is that after filling my istringstream with compression datas, I'm not able to convert this stream into an…
fcaillaud
  • 31
  • 7
1
vote
1 answer

C++ How to determine and report offset for current position in binary file using pubseekoff?

I have only been working with C++ for about 6 months so my apologies for any stupid mistakes I make in my code. I am working on a project that will read in a binary file to a streambuf and then search the streambuf for specific sequences and report…
DVS
  • 783
  • 7
  • 25
1
vote
1 answer

Writing a manipulator for a custom stream class

I've written a custom stream class that outputs indented text and that has manipulators that can change the indent level. All of the indenting work is implemented in a custom stream buffer class, which is used by the stream class. The buffer is…
AlexSilva
  • 94
  • 1
  • 11
1
vote
1 answer

Why basic_streambuf::pubseekoff() is not a pure virtual function?

If you look at header file in VS2010 you'll see the definition of this member function as pos_type pubseekoff(off_type _Off, ios_base::seekdir _Way, ios_base::openmode _Mode = ios_base::in | ios_base::out) { // change…
John Kalane
  • 1,163
  • 8
  • 17
1
vote
0 answers

Re-using a stringstream after iteration with istreambuf_iterator

If I pass an istreambuf_iterator wrapper around a stringstream to a function which requires such an iterator, how can I re-use (overwrite) the stream's existing buffer after the function has returned, without triggering a heap allocation? (clear…
user541686
  • 205,094
  • 128
  • 528
  • 886
1
vote
2 answers

Reading Binary Data with streambuf in C++ through a Class

Im am a c programmer trying to begin a new phase of my life in c++ (i know i am still using printf below, but that because formatting is so easy). I am looking to print out the first byte of a datafile from a member function of an object. I think…
Jon
  • 1,785
  • 2
  • 19
  • 33
1
vote
1 answer

cout a stringstream twice ends up in corrupted cout (minimal example)

I have the following code, and I dont quite understand why the results happens to be like the one below: #include #include using namespace std; int main () { std::stringstream s; std::streambuf *backup; backup =…
Gabriel
  • 8,990
  • 6
  • 57
  • 101