从Boost.regex的目录打印.pdf文件名 [英] Print .pdf filenames from a directory with Boost.regex

查看:200
本文介绍了从Boost.regex的目录打印.pdf文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

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 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)");

=

推荐答案

*。pdf 不是正则表达式,您需要

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

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




  • :匹配任何一个字符

  • * :0或以上的匹配
  • code> \\ :使一个 \ 用于转义(忽略下一个字符的正则表达式意义) li>

    • .: 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆