streambuf

initializing a C++ std::istringstream from an in memory buffer?

此生再无相见时 提交于 2019-11-27 04:16:34
I have a memory block (opaque), that I want to store in a Blob in mySQL through their C++ adapter. The adapter expects a istream: virtual void setBlob(unsigned int parameterIndex, std::istream * blob) = 0; So my question is: how can I create a std::istream from this memory block (typed as char*). It's not a string as it is not null-terminated (but I know its length of course). I could not find a way to do it without copying my memory block for example in a std::string. I think this is a bit wasteful. Something like this doesn't work: std::streambuf istringbuf(blockPtr, blockLength); std:

How do I create my own ostream/streambuf?

不问归期 提交于 2019-11-27 00:31:55
For educational purposes I want to create a ostream and stream buffer to do: fix endians when doing << myVar; store in a deque container instead of using std:cout or writing to a file log extra data, such as how many times I did <<, how many times I did .write, the amount of bytes I written and how many times I flush(). But I do not need all the info. I tried overloading but failed horribly. I tried overloading write by doing ostream& write( const char* s, streamsize n ) in my basic_stringstream2 class (I copied paste basic_stringstream into my cpp file and modified it) but the code kept using

C++ streams confusion: istreambuf_iterator vs istream_iterator?

微笑、不失礼 提交于 2019-11-26 15:23:48
问题 What is the difference between istreambuf_iterator and istream_iterator ? And in general what is the difference between streams and streambufs? I really can't find any clear explanation for this so decided to ask here. 回答1: IOstreams use streambufs to as their source / target of input / output. Effectively, the streambuf-family does all the work regarding IO and the IOstream-family is only used for formatting and to-string / from-string transformation. Now, istream_iterator takes a template

initializing a C++ std::istringstream from an in memory buffer?

南笙酒味 提交于 2019-11-26 11:08:07
问题 I have a memory block (opaque), that I want to store in a Blob in mySQL through their C++ adapter. The adapter expects a istream: virtual void setBlob(unsigned int parameterIndex, std::istream * blob) = 0; So my question is: how can I create a std::istream from this memory block (typed as char*). It\'s not a string as it is not null-terminated (but I know its length of course). I could not find a way to do it without copying my memory block for example in a std::string. I think this is a bit

How do I create my own ostream/streambuf?

只愿长相守 提交于 2019-11-26 09:23:59
问题 For educational purposes I want to create a ostream and stream buffer to do: fix endians when doing << myVar; store in a deque container instead of using std:cout or writing to a file log extra data, such as how many times I did <<, how many times I did .write, the amount of bytes I written and how many times I flush(). But I do not need all the info. I tried overloading but failed horribly. I tried overloading write by doing ostream& write( const char* s, streamsize n ) in my basic