boost-iostreams

How to pipe into std::cout with boost::iostreams

孤者浪人 提交于 2020-05-23 09:52:49
问题 I am new to boost::iostreams so this might be trivial: Assuming namespace io = boost::iostreams; this works io::filtering_ostream out(std::cout); out << "some\nstring\n"; and this works std::string result; io::filtering_ostream out(io::counter() | io::back_inserter(result)); out << "some\nstring\n"; yet this does not compile io::filtering_ostream out(io::counter() | std::cout); out << "some\nstring\n"; How do you pipe into std::cout ? 回答1: Wrapping std::cout with boost::ref worked for me: io:

warning message RTTI symbol not found when using boost::iostreams

喜欢而已 提交于 2020-01-14 08:59:12
问题 I use Boost::iostreams to write simultaneously to my console and a file. When i use eclipse to debug(with gdb of course), i receive a warning which says RTTI symbol not found for one of the classes that i am using from Boost::iostreams. Here is the minimal code to reproduce the problem. #ifndef BOOST_IO_STREAM_H_ #define BOOST_IO_STREAM_H_ #include <fstream> #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> using boost::iostreams::tee_device; using boost::iostreams:

Flushing a boost::iostreams::zlib_compressor. How to obtain a “sync flush”?

落花浮王杯 提交于 2020-01-03 11:54:53
问题 Is there some magic required to obtain a "zlib sync flush" when using boost::iostreams::zlib_compressor ? Just invoking flush on the filter, or strict_sync on a filtering_ostream containing it doesn't see to do the job (ie I want the compressor to flush enough that the decompressor can recover all the bytes consumed by the compressor so far, without closing the stream). Looking at the header, there seem to be some "flush codes" defined (notably a sync_flush ) but it's unclear to me how they

Flushing a boost::iostreams::zlib_compressor. How to obtain a “sync flush”?

泪湿孤枕 提交于 2020-01-03 11:53:43
问题 Is there some magic required to obtain a "zlib sync flush" when using boost::iostreams::zlib_compressor ? Just invoking flush on the filter, or strict_sync on a filtering_ostream containing it doesn't see to do the job (ie I want the compressor to flush enough that the decompressor can recover all the bytes consumed by the compressor so far, without closing the stream). Looking at the header, there seem to be some "flush codes" defined (notably a sync_flush ) but it's unclear to me how they

How to read a file into unsigned char array from std::ifstream?

旧巷老猫 提交于 2019-12-30 02:28:12
问题 So normaly I do stuff like: std::ifstream stream; int buff_length = 8192; boost::shared_array<char> buffer( new char[buff_length]); stream.open( path.string().c_str(), std::ios_base::binary); while (stream) { stream.read(buffer.get(), buff_length); //boost::asio::write(*socket, boost::asio::buffer(buffer.get(), stream.gcount())); } stream.close(); I wonder how to read into unsigned char buffer ( boost::shared_array<unsigned char> buffer( new unsigned char[buff_length]); ) 回答1: In a simplest

compile error for boost::iostream::filtering_streambuf

巧了我就是萌 提交于 2019-12-24 09:58:25
问题 Just trying to compress a string with bzip2 so that I can send it over a pipe with ReadFile. The following line earns me the following compile error. in.push(uncompressed_string); Error 6 error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE' c:\program files (x86)\boost\boost_1_47\boost\iostreams\chain.hpp 488 1 Agent boost::iostreams::filtering_streambuf<boost::iostreams::input> in; ostringstream uncompressed_string; ostringstream compressed_string; uncompressed_string << buf;

boost zlib problem

喜欢而已 提交于 2019-12-24 01:14:21
问题 I'm having a problem with the zlib libraries in boost under VS 2010. I built the libraries and the appropriate dlls/libs were generated in the boost/stage/lib folder. I added the .dlls into my programs debug folder and linked in the matching.lib. But I'm running into problems when I actually try to use the zlib streams. Heres an example: #include <cstring> #include <string> #include <iostream> #include <boost\iostreams\filter\gzip.hpp> #include <boost\iostreams\filtering_streambuf.hpp>

How to declare an “implicit conversion” in a variadic template?

本小妞迷上赌 提交于 2019-12-23 05:11:30
问题 My aim is to send a data to several streams. It is possible by using boost::tee. But I want to write a wrapper with variadic template for using several streams. The problem is that I need an implicit convertation from descendant struct to ancestor struct. Or something like that. #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> #include <fstream> #include <iostream> using namespace std; namespace bio = boost::iostreams; using bio::tee_device; using bio::stream; template

Does Boost.Serialization serialize differently on different platforms?

≯℡__Kan透↙ 提交于 2019-12-18 03:58:36
问题 I use Boost.Serialization to serialize a std::map. The code looks like this void Dictionary::serialize(std::string & buffer) { try { std::stringstream ss; boost::archive::binary_oarchive archive(ss); archive << dict_; buffer = ss.str(); } catch (const std::exception & ex) { throw DictionaryException(ex.what()); } } void Dictionary::deserialize(const char * const data, int length) { try { namespace io = boost::iostreams; io::array_source source(data, length); io::stream<io::array_source> in

Using boost::iostreams::mapped_file

这一生的挚爱 提交于 2019-12-14 03:56:50
问题 I am very new to the memory mapping and trying to understand memory mapped files to use them in my project(linux based). My requirement is to write & then read from memory mapped files. I wrote a sample program which only writes and it works fine but i have a few very basic doubts as i do not understand this funda of memory mapping properly. #include <unordered_map> #include <boost/iostreams/device/mapped_file.hpp> using namespace boost::interprocess; using namespace std; typedef unordered