Найти любой файл, заканчивающийся словом, Stack Overflow

Мне нужен эквивалент регулярного выражения ‘* bla.foo’, что означает, что вы получите все файлы, заканчивающиеся на bla.foo в c ++.

Что я придумал, так это:

#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')

Кажется, что неправильные аргументы передаются в функцию, я хотел бы знать, где я ошибся. Это мой первый код на с ++.

Спасибо!

-1

Решение

Если вы хотите сравнить строковые данные, вам нужно позвонить string() на ваше path объект:

    if (is_regular_file(*it) && boost::algorithm::ends_with(it->path().filename().string(), ext))
ret.push_back(it->path().filename());
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector