streambuf

inheriting ostream and streambuf problem with xsputn and overflow

∥☆過路亽.° 提交于 2019-12-06 02:47:44
问题 I have been doing research on creating my own ostream and along with that a streambuf to handle the buffer for my ostream. I actually have most of it working, I can insert (<<) into my stream and get strings no problem. I do this by implimenting the virtual function xsputn. However if I input (<<) a float or an int to the stream instead of a string xsputn never gets called. I have walked through the code and I see that the stream is calling do_put, then f_put which eventually tries to put the

What are 'aliased' stream buffers?

ε祈祈猫儿з 提交于 2019-12-05 23:18:54
What are 'aliased stream buffers`? I encountered the term in a comment on an answer of mine. James Kanze I've never heard the term before, but in the thread you cite, the person who used it also gave an example: two streams which use the same streambuf. Of course, just because two streams don't use the same streambuf, doesn't mean that data written to them doesn't ultimately end up in the same place; that they don't alias the same sink, if that is what is meant. There are filtering streambuf's, which forward the actual sinking and sourcing to another streambuf, and on most systems, it's

istream::tellg() returns -1 when used with my custom streambuf class?

♀尐吖头ヾ 提交于 2019-12-05 09:09:34
I'm trying to create an istream that reads directly from a raw memory buffer. I found a nice way to do this in another post on here: class membuf : public basic_streambuf<char> { public: membuf(char* p, size_t n) { setg(p, p, p + n); } }; Then I create my istream using this membuf : membuf mb(dataPointer, dataLength); istream reader(&mb); I then read using getline() and >> operators, and everything is wonderful. However, I can't seem to use seekg() to rewind back to the beginning of my buffer, and istream::tellg() always returns -1 . Do I need to write some more code to get these to work, or

What can go wrong if cout.rdbuf() is used to switch buffer and never set it back?

旧巷老猫 提交于 2019-12-05 08:13:29
The author presented this code under the title A bus error on my platform #include <fstream> #include <iostream> int main() { std::ofstream log("oops.log"); std::cout.rdbuf(log.rdbuf()); std::cout << "Oops!\n"; return 0; } The string "Oops!\n" is printed to the file "oops.log". The code doesn't restore cout's streambuf, but VS2010 didn't report a runtime error. Since log and std::cout share a buffer, that buffer will probably be freed twice (once when log goes out of scope, then once more when the program terminates). This results in undefined behavior, so it's hard to tell the exact reason

How do I implement seekg() for a custom istream/streambuf?

寵の児 提交于 2019-12-05 06:04:30
I used to be a C++ expert a decade ago, but for the past 10 years I've been programming Java. I just started a C++ project that uses a small third-party XML parser. The XML parser accepts an STL istream. My XML data is coming from a Windows COM IStream. I thought I'd do the Right Thing and create an adapter to take the IStream data and present it to the XML parser through an istream. I followed the excellent tutorial at http://www.mr-edd.co.uk/blog/beginners_guide_streambuf and created a COMStreambuf that takes data from the underlying COM IStream, and used it as a buffer for a custom

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

倖福魔咒の 提交于 2019-12-04 16:41:59
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 this: wifstream file; wstring line2; file.open("C:\\Users\\Mariusz\\Desktop\\zasoby.txt"); if(file.is_open()) { while(file.good()) { getline(file,line2); wcout << line2 << endl; } } file.close(); Even if the file is in ASCII. Right now I'm simply changing my string line to wstring with a function from this answer. However, I think if there is a way to

Use streambuf as buffer for boost asio read and write

痴心易碎 提交于 2019-12-04 10:16:42
问题 I'm using this code for reading socket_.async_read_some(boost::asio::buffer(data_, max_length), boost::bind(&session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); and this for writing boost::asio::async_write(socket_, boost::asio::buffer(data_, bytes_transferred), boost::bind(&session::handle_write, this, boost::asio::placeholders::error)); where socket_ is socket, max_length is enum with value 1024 and data_ is char array with length of

Binary version of iostream

时间秒杀一切 提交于 2019-12-04 07:55:36
问题 I've been writing a binary version of iostreams. It essentially allows you to write binary files, but gives you much control over the format of the file. Example usage: my_file << binary::u32le << my_int << binary::u16le << my_string; Would write my_int as a unsigned 32-bit integer, and my_string as a length-prefixed string (where the prefix is u16le.) To read the file back, you would flip the arrows. Works great. However, I hit a bump in the design, and I'm still on the fence about it. So,

inheriting ostream and streambuf problem with xsputn and overflow

不想你离开。 提交于 2019-12-04 05:30:13
I have been doing research on creating my own ostream and along with that a streambuf to handle the buffer for my ostream. I actually have most of it working, I can insert (<<) into my stream and get strings no problem. I do this by implimenting the virtual function xsputn. However if I input (<<) a float or an int to the stream instead of a string xsputn never gets called. I have walked through the code and I see that the stream is calling do_put, then f_put which eventually tries to put the float 1 character at a time into the buffer. I can get it to call my implementation of the virtual

Use streambuf as buffer for boost asio read and write

拟墨画扇 提交于 2019-12-03 06:13:35
I'm using this code for reading socket_.async_read_some(boost::asio::buffer(data_, max_length), boost::bind(&session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); and this for writing boost::asio::async_write(socket_, boost::asio::buffer(data_, bytes_transferred), boost::bind(&session::handle_write, this, boost::asio::placeholders::error)); where socket_ is socket, max_length is enum with value 1024 and data_ is char array with length of max_length. But I want to replace char array buffer with streambuf. I've tried boost::asio::streambuf