[英]Using boost IOStreams with std::ostream_iterator
I tried to use an array-device based stream and wantet to pass the stream to std::ostream_iterator
or std::istream_iterator
, but unfortunately, I get a compilation error with gcc 4.3.5.我尝试使用基于数组设备的 stream 并希望将 stream 传递给
std::ostream_iterator
或std::istream_iterator
,但不幸的是,我收到 ZE0D511356BD443B30Z4 的编译错误。
Boost::IOStreams documentation states that the io::stream
is either derived from std::basic_istream
or std::basic_ostream
or both ( std::basic_iostream
) dependent on the underlying device category. Boost::IOStreams 文档指出
io::stream
派生自std::basic_istream
或std::basic_ostream
或两者( std::basic_iostream
)取决于底层设备类别。 array device has seekable category, so I'd expect io::stream to derive from std::basic_iostream
and be compatible with std::ostream_iterator
or std::istream_iterator
.数组设备具有可搜索的类别,因此我希望 io::stream 派生自
std::basic_iostream
并与std::ostream_iterator
或std::istream_iterator
兼容。 But I unfortunately get a compilation error.但不幸的是,我得到了一个编译错误。
Here is the code snippet:这是代码片段:
namespace io=boost::io;
typedef unsigned char byte;
typedef io::basic_array<byte> array_device;
typedef io::stream<array_device> array_stream;
byte my_buffer[256]={};
array_stream ios_(my_buffer);
std::istream_iterator<byte> in(ios_);
And the last line results in the error stating:最后一行导致错误说明:
src/my_file.cpp: In member function 'void my_test_class::ctor::test_method()':
src/my_file.cpp:86: error: no matching function for call to
'std::istream_iterator<unsigned char, char, std::char_traits<char>, int>::istream_iterator(my_test_class::<unnamed>::array_stream&)'
You're not supplying enough template arguments for std::istream_iterator
-- the second argument is the underlying character type of the stream, which defaults to char
, but the underlying character type of your stream is byte
( unsigned char
).您没有为
std::istream_iterator
提供足够的模板 arguments - 第二个参数是 stream 的基础字符类型,默认为char
,但您的 ZF7B44CFAFD5C52223D549AZ 的基础字符类型是byte
( unsigned char
)。
Changing改变
std::istream_iterator<byte> in(ios_);
to至
std::istream_iterator<byte, byte> in(ios_);
should work.应该管用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.