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

C++: std::istream read and its calls to std::streambuf underflow

the following code simply tests how often underflow is called when using std::istream read on an std::stringbuf. #include #include #include class TestStringBuf : public std::stringbuf { public: int_type…
moka
  • 4,353
  • 2
  • 37
  • 63
1
vote
1 answer

c++ IPC through streambuf on Windows

I have a message object serialized as binary data stream (it can be any std::streambuf), and i want to transfer it to another process. The key is, server application must handle many clients, connection have to be asynchronous (because of multiple…
Frizi
  • 2,900
  • 1
  • 19
  • 25
1
vote
1 answer

Create a streambuf from const char* WITHOUT boost?

Same question as Create a streambuf from const char* except that I can't use boost. I have to implement an function that takes a const char * as input parameter, and to do so I have to call an other function that takes a istream as input…
Captain'Flam
  • 479
  • 4
  • 12
1
vote
1 answer

How can I specify the boost::asio::streambuf bufferstrm size globally

I know that we can specify the size of streambuf as below in some function boost::asio::streambuf bufferstrm(512); but in class how can we do the same thing class test{ public: boost::asio::streambuf bufferstrm; void func1(){ …
1
vote
0 answers

C++ std::streambuf::pubseekpos(): check if random access is supported

While writing a generic function taking a reference to an std::streambuf, I'd like to check if the supplied buffer is tied to something supporting random access or not and optimize the treatment accordingly, i.e. check if moving around the stream…
tomoyo255
  • 153
  • 1
  • 8
1
vote
2 answers

C++ Decorate basic_stream::underflow()

I want to extend the behavior of a basic_streambuf object by using the decorator pattern. That`s what I currently got: template class forwarding_basic_streambuf : boost::noncopyable, public…
0xbadf00d
  • 17,405
  • 15
  • 67
  • 107
1
vote
1 answer

convert image buffer to filestream

Something similar to this may have been asked earlier, I could not find an exact answer to my problem to decided to ask here. I am working with a 3rd party framework that has it's own classes defined to handle image files. It only accepts the file…
gamadeus
  • 251
  • 3
  • 11
1
vote
2 answers

How to add argument to stream buffer c++

I just want a way to have a function ( or anything else ) which have one standard argument and another one coming from the operator <<. my_comp(argument) << "HelloWorld" ; The goal is to purpose a Logger class that any other class can easily…
Goozzi
  • 209
  • 1
  • 7
1
vote
1 answer

std::clog wrapper with color and header fails to print integers properly

I need a class to wrap calls to std::clog so that: Each message is prefixed by a header that includes time and the name of the entity that generated the message. Messages are coloured in accordance to error types (e.g. debug, warning, error). The…
Carles Araguz
  • 1,157
  • 1
  • 17
  • 37
1
vote
3 answers

Create a logging object with std::stream interface

Internally we have a logging function with the interface OurLog(const char *). I'd like to be able to use it with an interface similar to std::ostringstream. In other words, I'd love to have an adaptor object so I can write: logging_class log; log…
leecbaker
  • 3,611
  • 2
  • 35
  • 51
1
vote
2 answers

Writing char* into a basic_streambuf and assign it to a ifstream

I have a problem, mostly because I can't really understand how to handle the situation. I have a char* buffer of X size, it's the content of an encrypted file who's got decrypted and will be then parsed by the ifstream handler class that i can't…
d3vil401
  • 51
  • 6
1
vote
0 answers

Rollback decorator for std::streambuf for backtracking in a parser library

I'm trying to implement a general parser library for purely educational purposes. The parsers are supposed to operate on arbitrary std::istreams. So far I've been able to get it to work for all LL(1) languages by using istream::unget to rollback the…
Corristo
  • 4,911
  • 1
  • 20
  • 36
1
vote
3 answers

boost::asio::async_read and boost::asio::streambuf

I am using async_read with streambuf. However, I would like to limit the amount of data read to 4, so I can properly handle header before going to body. How can I do that using async_read?
Vladimir
  • 191
  • 1
  • 9
1
vote
1 answer

C++ STL streambuf exception handling

Here I have this streambuf, ostream structure (modified from here http://wordaligned.org/articles/cpp-streambufs), where I try to throw from two points in the code. But I never can catch those exceptions in the main() and the program exits normally.…
hovnatan
  • 1,331
  • 10
  • 23
1
vote
1 answer

std::streambuf::in_aval always returns 0 for std::ostream

My goal is to get data stored in streambuf. My idea is getting streambuf by rdbuf and then getting data using sgetn. class mystreambuf : public std::streambuf {} mystreambuf strbuf; std::ostream os(&strbuf); os << "1234567890"; std::streambuf *sb =…
Ir S
  • 445
  • 1
  • 6
  • 19