7

プログラム内でブースト正規表現を使用しようとしていますが、問題はこのエラーが発生することです...インストール手順は「C:\ ProgramFiles \ boost\boost_1_42」を追加のインクルードディレクトリに追加することだけでした...

私はVS2008を使用しています...

これを実装しようとしています:

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using namespace std;

int main( ) {

   std::string s, sre;
   boost::regex re;
   boost::cmatch matches;

   while(true)
   {
      cout << "Expression: ";
      cin >> sre;
      if (sre == "quit")
      {
         break;
      }

      cout << "String:     ";
      cin >> s;

      try
      {
         // Assignment and construction initialize the FSM used
         // for regexp parsing
         re = sre;
      }
      catch (boost::regex_error& e)
      {
         cout << sre << " is not a valid regular expression: \""
              << e.what() << "\"" << endl;
         continue;
      }
      // if (boost::regex_match(s.begin(), s.end(), re))
      if (boost::regex_match(s.c_str(), matches, re))
      {
         // matches[0] contains the original string.  matches[n]
         // contains a sub_match object for each matching
         // subexpression
         for (int i = 1; i < matches.size(); i++)
         {
            // sub_match::first and sub_match::second are iterators that
            // refer to the first and one past the last chars of the
            // matching subexpression
            string match(matches[i].first, matches[i].second);
            cout << "\tmatches[" << i << "] = " << match << endl;
         }
      }
      else
      {
         cout << "The regexp \"" << re << "\" does not match \"" << s << "\"" << endl;
      }
   }
}

問題であると想定されるのは ?追加の設定を行う必要がありますか?

4

4 に答える 4

14

一部のBoostライブラリを構築する必要があります。これはそのうちの1つです。それらを構築する方法は次のとおりです。

と呼ばれる新しいファイルを作成しboost_build.bat、内部に次のように入力します。

bjam toolset=msvc-9.0 variant=release threading=multi link=static define=_SECURE_SCL=0 define=_HAS_ITERATOR_DEBUGGING=0
bjam toolset=msvc-9.0 variant=debug threading=multi link=static

注9.0はVS2008を指します(2010年は10.0、2005年は8.0、2003年は7.1、6.0は6.0)。これを行ったら:

  1. build_boost.batに抽出<boost_root>

  2. 移動: <boost_root>\tools\jam そして実行build_dist.bat

  3. <boost_root>\tools\jam\stage\bin.ntx86\bjam.exeにコピー<boost_root>

  4. 走るboost_build.bat

  5. ライブラリはにあります<boost_root>\stage\lib

これは私自身の方法であることに注意してください。誰かがもっと簡単な方法でチャイムを鳴らしたり、BoostからのリンクがあればいいのですがBoostから適切なビルド手順を見つけるのは難しいようです。

ビルドしたら、ライブラリがVCディレクトリ(ライブラリパス)のどこにあるかをコンパイラに通知してください。""を追加し<boost_root>\stage\libます。


bjam定義では、リリース用に持っています_SECURE_SCL=0 _HAS_ITERATOR_DEBUGGING=0。これにより、リリースビルドのすべてのイテレータチェックが無効になり、速度が向上します。

于 2010-02-16T16:06:39.183 に答える
2

Windowsでは、ブーストバイナリライブラリを取得する最も簡単な方法は、BoostProコンサルティングからインストーラーを実行することです。インストール中に、必ずVisual Studioのバージョンを選択し、正規表現ライブラリのチェックボックスをオンにしてください。

于 2011-09-18T12:53:04.893 に答える
1

Boostのマルチスレッドデバッグバージョンをインストールしましたか?そうでない場合は、そうしてください。それ以外の場合は、(プロジェクト設定で)ライブラリパスをチェックして、エラーメッセージに記載されているファイルへのパスが含まれるようにします。

于 2010-02-16T16:03:03.237 に答える
0

<boostroot>\bootstrap定義の設定についてはよくわかりませんが、バッチファイルを実行し、次のようにファイルを編集することで、MSVC9.0でビルドするためのブーストを得ることができました<boostroot>\project-config.jam。行を変更します。

using mvsc

に:

using msvc : 9.0 : cl.exe

次に実行する.\b2 installと、ブーストヘッダーとライブラリがビルドされてにインストールされましたc:\boost

于 2012-06-23T06:50:08.903 に答える