使用迭代器打印multimap
Using iterator to print a multimap
假设我有一些
typedef std::pair<userObject*,char> Bar;
std::multimap<int, Bar > Foo;
std::multimap<int, Bar >::iterator it = foo.begin();
我已经在map中插入了一些成员,并且想使用迭代器遍历它的内容。但是,尝试第二行代码会产生no viable conversion from....
我知道错误是由Bar
是一对引起的。我用ints
写了一个简单的类来模拟行为,一切都如预期的那样工作。我是否需要提供一些模板类T?定义行为。
这里是源代码的链接,可以查看代码。
错误信息是
no viable conversion from '__map_iterator<__tree_iterator<__value_type<int *, [...]>, std::__1::__tree_node<std::__1::__value_type<int *, std::__1::pair<Vertex *, char> >, void *> *, [...]>>' to '__map_iterator<__tree_iterator<__value_type<int, [...]>, std::__1::__tree_node<std::__1::__value_type<int, std::__1::pair<Vertex *, char> >, void *> *, [...]>>'
这并不是因为它们是一对。这是因为您没有调用函数foo。开始,而不是尝试直接访问它。
正确的代码是std::multimap<int, Bar >::iterator it = foo.begin();
相关文章:
- 如何循环打印顶点结构
- 使用std::multimap迭代器创建std::list
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 如何在c++中打印目录
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 在线编译器中的分段C++没有打印消息
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 如何将结构插入到集合中并打印集合的成员
- 在循环C++中指定字符串之后,不会打印该字符串
- 以螺旋方式打印矩阵的程序.(工作不好)
- 从控制台中删除最后打印的元素
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 如何仅使用对象名称打印特定于对象的成员
- 回溯C++不打印函数,因此文件
- 在一定长度后从数组中打印时缺少整数
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 使用迭代器打印multimap
- 按字母顺序打印std::multimap键和值
- 使用multimap在c++中读取并打印一个超过2列的csv文件