c++ - 如何访问其中有一对的 map

标签 c++ stdmap std-pair

我正在使用里面有pair的 map , 但无法弄清楚如何使用 map 迭代器进行访问

我的 map 声明

  map<ll,pair<ll,ll> > val;
  map<ll,pair<ll,ll> > ::iterator it;      

我用来访问插入值的是

   cout<<it->first<<" " <<it->second->first<<" " <<it->second->second<<endl;

但编译器显示此错误

error: base operand of '->' has non-pointer type 'std::pair<long long unsigned int, long long unsigned int>'|

最佳答案

使用.访问一对元素。

cout<<it->first<<" " <<it->second.first<<" " <<it->second.second<<endl;

关于c++ - 如何访问其中有一对的 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42184477/

相关文章:

c++ - 从 C++ 中的对 vector 生成组 vector

c++ - 将一对 move 到 vector 中

c++ - 为什么不为 std::tuple 重载 STL 算法?

c++ - 如何从 C 调用 C++ 函数?

C++ vector 、指针等

c++ - 将 map 的键集转换为键 vector 的有效方法是什么

c++ - 以列表作为值初始化 map

c++ - Visual C++ 编译器是否优化了未定义的宏 block ?

c++ - 逐元素 vector 乘法

c++ - 无法创建 MoveConstructibles 的 map