Boost logo

Boost Users :

From: Christian Henning (chhenning_at_[hidden])
Date: 2006-03-22 10:38:30


Andrew, the following code is not working on my machine. Can you check
if it is on your machine, please? The size of the match container is
just one. I'm using VC7.1 and Boost 1.33.1.

int _tmain(int argc, _TCHAR* argv[])
{
   //second approach
   boost::regex oDateReg2( "\\d{2}-\\d{2}-\\d{4}" );
   std::string strDate2( "11-22-1997" );

   boost::smatch dateMatch;

   if( boost::regex_match( strDate2
                         , dateMatch
                         , oDateReg2 ))
   {
      try
      {
         size_t nMatchSize = dateMatch.size();

         if( nMatchSize >= 4 )
         {
            std::string strMonth = dateMatch[1];
            std::string strDay = dateMatch[2];
            std::string strYear = dateMatch[3];

            unsigned int nYear = boost::lexical_cast<unsigned int>( strYear );
            unsigned int nMonth = boost::lexical_cast<unsigned int>( strMonth );
            unsigned int nDay = boost::lexical_cast<unsigned int>( strDay );

            date d( nYear, nMonth, nDay );

            date::ymd_type ymd = d.year_month_day();
         }
         else
         {
            std::cerr << "Error. ";
         }
      }
      catch( std::out_of_range oEx )
      {
         std::cout << "Error: " << oEx.what() << std::endl;
      }
      catch( std::exception oEx )
      {
         std::cout << "Error: " << oEx.what() << std::endl;
      }
   }

        return 0;
}

When I run the captures_examples of the regex lib the smatch stuff
works. But not here. Very strange.

Thanks,
Christian


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