c++ - 迭代 std::map,做错事,提示迭代器缺少 '=' 运算符

标签 c++ dictionary stl iterator

这是我的功能:

friend std::ostream& operator<< (std::ostream& stream, const Path& path) {
    std::map<double, glm::vec3>::iterator iter;
    for (iter = path.points.begin(); iter != path.points.end(); iter++){
        stream << "test" << "\n";
    }
}

这是我的错误:

Error   1   error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>' (or there is no acceptable conversion) c:\users\adam\skydrive\documents\proj\ray\ray\path.h    22  1   ray

我以前从来没有遇到过这种问题。老实说,我不知道从哪里开始。我尝试了几种获取迭代器的方法,包括 typedef 方法,但同样的问题仍然存在。

有什么建议吗?

最佳答案

Pathconst,因此您使用的是 .begin()const 版本。但是您正在尝试将其分配给可变迭代器。尝试将 iter 声明为 Path::const_iterator

关于c++ - 迭代 std::map,做错事,提示迭代器缺少 '=' 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23236317/

相关文章:

c++ - 如何使函数不使用 STL 容器参数(类似于空指针)?

c++如何打印每个整数在STL列表中出现的次数

c++ - 边缘相交算法?

c++ - 是否有 std::memset 等同于 std::array?

c++ - 需要帮助 do-while 循环程序吗? (C++)

python - 循环遍历多个不同大小的Python字典

c - Unload() 递归 C Segfault(类似 TRIE 的数据库) CS50 pset5

c++ - 使用 QStandardItem 传输自定义数据 (Type*) 时内存泄漏?

javascript - 如何在 leaflet.js 中使用动画 gif 磁贴

c++ - C++ 中的 key_compare 与 key_comp