【问题标题】:Display a map of two vectors显示两个向量的映射
【发布时间】:2015-06-02 16:30:57
【问题描述】:

我想显示我的两个向量图。 请你帮帮我。

 std::map<vector<double>,vector<int>> path;

谢谢

【问题讨论】:

  • “显示”是什么意思?
  • 在控制台中查看输出
  • 迭代 std::map 的键和值,然后按每个键和每个值进行迭代。
  • 是的,谢谢我在考虑这个

标签: c++ dictionary vector


【解决方案1】:

可能有很多方法可以做到这一点。这是一个:

template<class T> void dumpVector( const std::vector<T>& vect )
{
    for ( std::vector<T>::const_iterator iter = vect.begin();
          iter != vect.end();
          ++iter )
    {
        std::cout << " " << *iter;
    }
}

for ( std::map<vector<double>,vector<int>>::const_iterator mapIter = path.begin();
      mapIter != path.end();
      ++mapIter )
{
    std::cout << "Map key:";
    dumpVector<double>( mapIter->first );
    std::cout << " has value:";
    dumpVector<int>( mapIter->second );
    std::cout << std:endl;
}

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多