从Boost.regex目录打印.PDF文件名 [英] Print .pdf filenames from a directory with Boost.regex
本文介绍了从Boost.regex目录打印.PDF文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的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;
}
}
但我总是和中止()在Visual Studio中的错误,运行该程序后,这个问题是在这一行:
But I always get and Abort() error in Visual Studio, after running the program, the problem is in this line:
boost::regex reg("(*.pdf)");
我这不是声明regex对象好不好?
Am I not declaring the regex object good ?
推荐答案
*。PDF
不是一个正则表达式,这是一个水珠(文件匹配)。您需要
*.pdf
isn't a regex, it's a glob (for file matching). You need
boost::regex reg("(.*\\.pdf)");
-
-
*
:0以上的previous匹配 -
\\\\
:使一个单一的\\
转义(忽略下一个字符的正则表达式的含义) .
: 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)
这篇关于从Boost.regex目录打印.PDF文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文