【问题标题】:Displaying contents of 2D iterator C++11显示 2D 迭代器 C++11 的内容
【发布时间】:2013-08-14 03:22:29
【问题描述】:

我一直在看这个:Iterator for 2d vector

并想问是否可以显示 2D 迭代器的内容:

template<typename Inverse>
MFCC(Inverse begin, Inverse end, Struct::returnType type)
{   
  for(auto row = begin; (row != end); row++)
  {
      for(auto col = row->begin(); col != row->end(); col++) {


      }
  }
}

我已经(认真地)尝试了以下方法:

std::cout &lt;&lt; *row*col &lt;&lt; endl;

但没有喜悦,我敢肯定它正打在我脸上,但我只是想问一下。

【问题讨论】:

    标签: c++11 iterator


    【解决方案1】:

    你试过了吗?

    template<typename Inverse>
    void MFCC(Inverse begin, Inverse end)
    {   
      for(auto row = begin; (row != end); row++)
      {
          for(auto col = row->begin(); col != row->end(); col++) {
            std::cout<<*col<<" ";
          }
          std::cout<<std::endl;
      }
    }
    
    
    //MFCC(vec.begin(),vec.end());
    

    不确定 Struct::returnType 是什么,您可能可以解决。

    【讨论】:

    • 谢谢,太好了!但是,为什么只是*col tho?另外Struct::returnType 只是一个enum 来确定数据是否应该存储为arrayvector,但这很棒!
    • @Phorce 谢谢,你有一个向量的向量,使用 *col 只有你可以访问元素。
    • 现在说得有道理,我有时很愚蠢!接受你的回答
    猜你喜欢
    • 2012-04-19
    • 2014-04-04
    • 2012-11-07
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 1970-01-01
    相关资源
    最近更新 更多