c++ - Print .pdf filenames from a directory with Boost.regex -


this code:

path path = "e:\\documents\\"; boost::regex reg("(*.pdf)"); for(recursive_directory_iterator it(path); != recursive_directory_iterator(); ++it) {     if(boost::regex_search(it->string(), reg))     {         cout << *it << endl;     } } 

but , abort() error in visual studio, after running program, problem in line:

boost::regex reg("(*.pdf)"); 

am not declaring regex object ?

*.pdf isn't regex, it's glob (for file matching). need

boost::regex reg("(.*\\.pdf)");  
  • .: matches 1 character
  • *: 0 or more of previous match
  • \\: make single \ escaping (ignore regex meaning of next character)

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -