使用Boost.regex从目录中打印.pdf文件名
Print .pdf filenames from a directory with Boost.regex
这是我的代码:
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;
}
}
但是我总是得到和Abort()错误在Visual Studio中,运行程序后,问题在这一行:
boost::regex reg("(*.pdf)");
*.pdf
不是正则表达式,它是一个glob(用于文件匹配)。你需要
boost::regex reg("(.*\.pdf)");
-
.
:匹配任意一个字符 -
*
: 0个或以上的前一个匹配 -
\
:生成单个用于转义(忽略下一个字符的正则表达式含义)
相关文章:
- 如何循环打印顶点结构
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 如何在c++中打印目录
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 在线编译器中的分段C++没有打印消息
- 如何使用打印到 PDF 打印机在 MFC 和 CView 中以编程方式打印而不提示输入文件名?
- 将 QTableWidget 内容打印为 PDF
- 从QT打印PDF文件
- 如何使用QPainter将多个Qwidgets在不同页面中打印到PDF
- 如何判断Microsoft打印到 PDF 打印机驱动程序何时完成
- 使用 QT 打印为 pdf
- 使用 Qt 打印 PDF 文件
- cmd.exe打开PDF并打印它
- 使用libharu在pdf中打印日语字符
- 在 Mac 上检测 PDF 打印
- Libharu pdf创建:如何知道打印文本的大小
- 使用MFC打印PDF文件
- 如何在Qt中打印pdf文件
- 使用 C++ 在打印机上可视化打印 PDF 文件
- 使用Boost.regex从目录中打印.pdf文件名