【发布时间】:2017-10-24 17:32:20
【问题描述】:
我想要正则表达式“*bla.foo”的等价物,这意味着在 c++ 中获取所有以 bla.foo 结尾的文件。
到目前为止我想出的是:
#define BOOST_FILESYSTEM_VERSION 3
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/predicate.hpp>
void get_all(const fs::path& root, const std::string& ext, std::vector<fs::path>& ret)
{
if(!fs::exists(root) || !fs::is_directory(root)) return;
fs::recursive_directory_iterator it(root);
fs::recursive_directory_iterator endit;
while(it != endit)
{
if(fs::is_regular_file(*it) && boost::algorithm::ends_with(it->path().filename(), ext)) ret.push_back(it->path().filename());
++it;
}
}
但我收到错误:
namespace boost {
namespace algorithm {
// is_equal functor -----------------------------------------------//
//! is_equal functor
/*!
Standard STL equal_to only handle comparison between arguments
of the same type. This is a less restrictive version which wraps operator ==.
*/
struct is_equal
{
//! Function operator
/*!
Compare two operands for equality
*/
template< typename T1, typename T2 >
bool operator()( const T1& Arg1, const T2& Arg2 ) const
{
return Arg1==Arg2;
}
};
错误是:
/usr/local/include/boost/algorithm/string/compare.hpp:43:28:
Invalid operands to binary expression ('const boost::filesystem::path' and 'int')
似乎错误的参数被传递给函数,我想知道我哪里出错了。这是我的第一个 c++ 代码。
谢谢!
【问题讨论】: