Boost logo

Boost Users :

From: aitors2002 (aitors2002_at_[hidden])
Date: 2003-04-03 09:20:33


--- In Boost-Users_at_[hidden], "aitors2002" <aitors2002_at_y...> wrote:
>
> Hello, the next program doesn't work. It should print all the lines except the ones starting with '#'.
> It does work in perl :
> $ perl -ne 'print unless /^\s*\#/' a.cc
>
> why ?
>
> Thank you
> aitor
>
> -------------------
> // a.cc
> #include<iostream>
> #include<fstream>
> #include<string>
> #include<vector>
> #include<boost/regex.hpp>
>
> int main() {
>
> using namespace std;
>
> ifstream f("a.cc");
> string l;
> vector<string> v;
> static const boost::regex r("^\\s*\\#", boost::regbase::escape_in_lists |
> boost::regbase::perl);
>
> while(f) {
> getline(f,l,'\n');
> if (boost::regex_match(l,r)) continue;
> v.push_back(l);
> }
> for(vector<string>::const_iterator it = v.begin();
> it != v.end(); ++it)
> cout << *it << endl;
> }

Hello again,

the problem was because of using regex_match instead of regex_search,
since regex_match requires that the whole string matches.

Thank you for the help

                         aitor


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