0

ある程度のドキュメントを読みましたが、VS2010に付属している現在のバージョンについて詳しく知っています。しかし今のところ、私はubuntu 8.04で立ち往生しており、1.34をブーストしていて、奇妙な種類のエラーが発生しています。誰かが私が間違っていることを言うことができますか?これがregex_searchboostv1.34のマニュアルページです。

これが私のコードで行っていることです:

std::string sLine;
getline(dataFile, sLine);
boost::match_results<std::string::const_iterator> lineSmatch; 
boost::match_flag_type regFlags = boost::match_default;    
boost::regex finalRegex(linePattern);

boost::regex_search(sLine.begin(), sLine.end(), lineSmatch, finalRegex, regFlags);

コンパイルエラーは次のとおりです。

エラー:'regex_search(__ gnu_cxx :: __ normal_iterator、std :: allocator >>、__gnu_cxx :: __ normal_iterator、std :: allocator >>、boost :: match_results <__ gnu_cxx :: __ normal_iterator、std::allocatorを呼び出すための一致する関数がありません>、std :: allocator、std :: allocator >> >> >>&、boost :: regex&、boost :: regex_constants :: match_flag_type&) '

4

2 に答える 2

1

ハワードが答えたように、範囲ではなくそれ自体に 適用する場合はregex_search、andの代わりに 使用できます。 例えば:sLineiteratorsLinebegin()end()

boost::regex_search(sLine, lineSmatch, finalRegex, regFlags);

iteratorにrange を指定する必要がある場合は、regex_searchの型引数が でmatch_resultsあるためconst_iterator、 の 1 番目と 2 番目の引数もregex_search必要const_iteratorです。
例えば:

std::string::const_iterator b = sLine.begin(), e = sLine.end();
boost::regex_search(b, e, lineSmatch, finalRegex, regFlags);

お役に立てれば

于 2011-03-28T16:59:34.767 に答える
0

特にubuntu 8.04とboost 1.34では役に立ちません。ただし、以下は C++11 を実装するlibc++でコンパイルされます。おそらく、あなたの環境に十分近いので、何が悪いのかがわかります。

#include <regex>
#include <fstream>

int main()
{
    std::ifstream dataFile;
    std::string sLine, linePattern;
    getline(dataFile, sLine);
    std::match_results<std::string::const_iterator> lineSmatch; 
    std::regex_constants::match_flag_type regFlags = 
                                        std::regex_constants::match_default;    
    std::regex finalRegex(linePattern);

    std::regex_search(sLine, lineSmatch, finalRegex, regFlags);
}
于 2011-03-28T15:26:37.367 に答える