title: C++; Iterate over vector of structs and access struct members
body: <p>I have a struct:</p>
  
  <pre><code>struct fsobject {
  std::string fqname; //Fully Qualified Name of File incl extension
  std::string type;   //Type of Object, Either Directory or File
  std::string data;   //contents of file. Directories have no data.
  };
  </code></pre>
  
  <p>And a vector of type fsobject:</p>
  
  <pre><code>std::vector&lt;fsobject&gt; driveA;//Drive A
  </code></pre>
  
  <p>I am trying to iterate over the vector and access struct members for each vector element. This is the loop I have created:</p>
  
  <pre><code>for (auto vectorit = driveA.begin(); vectorit != driveA.end(); ++vectorit)
  {
      cout &lt;&lt; vectorit.fqname &lt;&lt;endl;
  }
  </code></pre>
  
  <p>Which results in the error:</p>
  
  <p>main.cpp|50|error: ‘class __gnu_cxx::__normal_iterator >’ has no member named ‘fqname’|</p>
  
  <p>I am having a hard time wrapping my head around how to accomplish accessing members of each vector element. Any help is appreciated.</p>
  
  <p>Here is the full source:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;cctype&gt;
  #include &lt;vector&gt;
  
  struct fsobject {
  std::string fqname; //Fully Qualified Name of File incl extension
  std::string type;   //Type of Object, Either Directory or File
  std::string data;   //contents of file. Directories have no data.
  };
  
  
  using namespace std;
  
  bool compare(const fsobject&amp; first, const fsobject&amp; second)
  {
    if (first.fqname &lt; second.fqname)
      return true;
    else
      return false;
  }
  
  int main()
  {
  
      std::vector&lt;fsobject&gt; driveA;//Drive A
      std::vector&lt;fsobject&gt; driveB;//Drive B
      std::vector&lt;fsobject&gt; driveC;//Drive C
  
      driveA.push_back({"/home/zory/","dir",""});
      driveA.push_back({"/home/dory/","dir",""});
      driveA.push_back({"/home/","dir",""});
      driveA.push_back({"/home/anakin/","dir",""});
      driveA.push_back({"/home/luke/","dir",""});
      driveA.push_back({"/home/luke/","dir",""});
      driveA.push_back({"/home/luke/QuaterlyReports.pdf","file","bankruptcy is coming"});
  
      sort(driveA.begin(),driveA.end(),compare);
      /*cout &lt;&lt; driveA.back().fqname &lt;&lt; endl;
      driveA.pop_back();
      cout &lt;&lt; driveA.back().fqname &lt;&lt; endl;*/
  
  
  
      for (auto vectorit = driveA.begin(); vectorit != driveA.end(); ++vectorit)
      {
          cout &lt;&lt; vectorit.fqname &lt;&lt;endl;
      }
  
  
      cout &lt;&lt; "Done...";
  
      return 0;
  }
  </code></pre>
  
  <p>Thanks!</p>