This is my code:
path Path = "e:\\Documents\\";
boost::regex reg("(*.pdf)");
for(recursive_directory_iterator it(Path); it != recursive_directory_iterator(); ++it)
{
if(boost::regex_search(it->string(), reg))
{
cout << *it << endl;
}
}
But I always get and Abort() error in Visual Studio, after running the program, the problem is in this line:
boost::reg开发者_StackOverflow中文版ex reg("(*.pdf)");
Am I not declaring the regex object good ?
*.pdf
isn't a regex, it's a glob (for file matching). You need
boost::regex reg("(.*\\.pdf)");
.
: matches any one character*
: 0 or more of the previous match\\
: to make a single\
for escaping (ignore the regex meaning of the next character)
精彩评论