c++ - boost 目录迭代器错误 : no match for operator! =

标签 c++ boost

我刚刚开始接触 C++ boost 库。我遇到了 directory_iterator 和 recursive_directory_iterator 的问题。当我尝试编译以下代码时,我总是得到与运算符不匹配的结果!=。我也尝试过==没有成功。

const boost::filesystem::recursive_directory_iterator end();
for(boost::filesystem::recursive_directory_iterator i(p); i != end; i++){
    if(boost::filesystem::is_regular_file(i->status())){
        cout << i->path().filename() << endl;
    }
}

有什么帮助吗? 谢谢!

最佳答案

const boost::filesystem::recursive_directory_iterator end()没有定义变量end相反,它声明了函数end的函数原型(prototype)。它返回 const boost::filesystem::recursive_directory_iterator并且不接受任何参数(搜索“C++ 最令人烦恼的解析”以了解为什么会发生这种情况)。将其更改为 const boost::filesystem::recursive_directory_iterator end; .

关于c++ - boost 目录迭代器错误 : no match for operator! =,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10891561/

相关文章:

c++ - 将树数据结构转储到文件或从文件恢复树数据结构

c++ - 类之外的运算符重载!

c++ - Boost线程、Posix线程和STD线程,为什么它们提供不同的性能?

c++ - boost 线程和 shared_ptr

c# - boost proto vs c# 表达式树

c++ - 使用 boost::numeric::odeint 积分非线性函数 f'(x, y, z) = a + b*I

c++ - 更改来自另一个类的标签文本

c++ - 为什么我在使用++ 时出现段错误,但在使用 '1 +' 时却没有?

c++ - 使用 convertTo 从 CV_16SC1 转换为 CV_32FC1

c++ - boost::weak_ptr 会抛出异常吗?