Boost logo

Boost Users :

From: Tobi (tobias.paesler_at_[hidden])
Date: 2005-12-02 07:21:32


Hello,

this is my my first post to a newsgroup, so i hope it will work...
I use the boost regex library, and i was wondereing, why the following
code doesn't work.
When i output the result of the match, it should output "a", but it
didn't, the output was something wrong like "yl".
I figured out, that the reasen for this is, that the string sSearchString
is just in the scope of the try-block, so it is allready destroyed when i
do the output. If i put the declaration of the string above the try block,
all works fine, because the searchstring is still existing when i do the
output.
The matchresult seems to save just a reference to the string.
Am i doing sth wrong? I think this is quite dangerous, or is there a way
to do this more safe?

Thanx, Tobi

///////////////////////////////////////////
      boost::smatch match; // Match-Ergebnis
      bool bMatched;

      try
      {

          // Regulaeren Ausdruck anlegen
          boost::regex sExpr;
          sExpr.assign( "." );

          // Suchstring anlegen
          std::string sSearchString = "abcdef";

          // Matchen
          bMatched = boost::regex_search(sSearchString,match,sExpr);

      }
      catch(runtime_error& er)
      {
          m_sLog = er.what();
          return;
      }

      if( bMatched )
      {
                cout << match[0] << endl;
       }
///////////////////////////////////////////


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net