[英]compile error on boost::iostreams::copy
我试图通过一些例子来学习boost :: iostreams。 这是gcc不能接受的其中一个:
#include <iostream>
#include <boost/iostreams/filter/regex.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
using namespace std;
int main()
{
boost::regex reg("a.c");
string str("abcdef aochijk");
string result;
boost::iostreams::copy(
boost::make_iterator_range(str),
boost::iostreams::filtering_ostream(
boost::iostreams::regex_filter(reg,"test") |
boost::iostreams::back_inserter(result))
);
cout<<result<<endl;
return 0;
}
这是错误:
error:no matching function for call to 'copy(boost::iterator_range<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >, boost::iostreams::filtering_ostream)'
error:no type named 'type' in 'struct boost::disable_if<boost::iostreams::is_std_io<boost::iostreams::filtering_stream<boost::iostreams::output> >, void>'
我的clang副本也没有编译它,告诉我note: candidate function [snip] not viable: expects an l-value for 2nd argument
。
这对我来说似乎很合理,事实上,这个编译:
boost::regex reg("a.c");
string str("abcdef aochijk");
string result;
boost::iostreams::filtering_ostream ios(
boost::iostreams::regex_filter(reg,"test") |
boost::iostreams::back_inserter(result));
boost::iostreams::copy( boost::make_iterator_range(str), ios);
#include <iostream>
#include <boost/iostreams/filter/regex.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
using namespace std;
int main()
{
boost::regex reg("a.c");
string str("abcdef aochijk");
string result;
boost::iostreams::filtering_ostream fos(boost::iostreams::regex_filter(reg,"test") |
boost::iostreams::back_inserter(result)) ;
boost::iostreams::copy(boost::make_iterator_range(str),fos);
cout<<result<<endl;
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.