1

私はいくつかの例でboost::iostreamsを学ぼうとしています。gccで受け入れられないものの1つを次に示します。

#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>'
4

2 に答える 2

2

私の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);
于 2013-03-24T15:52:51.027 に答える
1
#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;
}
于 2013-03-24T15:56:39.447 に答える