title: C++ problem to write vector data to file
body: <p>I want to write the content of the vector v to a file. Problem is that not the content but the address will be placed inside the textfile. </p>
  
  <p>When I write *pos inplace of &amp;pos I get the error: <em>error C2679: binary '&lt;&lt;' : no operator found which takes a right-hand operand of type 'entry'</em> </p>
  
  <p>How does it work correct?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;limits&gt;
  
  /*
  Data.txt 
  
  John
  6543
  23
  
  Max
  342
  2
  
  A Team
  5645
  23
  */
  
  struct entry
  {
      // passengers data
      std::string name;
      int weight; // kg
      std::string group_code; 
  };
  
  void reservations(std::vector&lt;entry&gt; v)
  {
      std::ofstream outfile;
      outfile.clear();
      outfile.open("reservations.txt");
      // print data in vector
      std::vector&lt;entry&gt;::iterator pos;
          for (pos = v.begin(); pos!= v.end();++pos)
          {
              outfile &lt;&lt; &amp;pos &lt;&lt; std::endl;
              std::cout &lt;&lt; &amp;pos &lt;&lt; std::endl;
          }
      outfile.close();
  }
  
  entry read_passenger(std::ifstream &amp;stream_in)
  {
      entry passenger;
      if (stream_in)
      {
          std::getline(stream_in, passenger.name); 
          stream_in &gt;&gt; passenger.weight;
          stream_in.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
          std::getline(stream_in, passenger.group_code);
          stream_in.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
          return passenger;
      }
  
      return passenger; 
  }
  
  int main(void)
  {
      std::ifstream stream_in("data.txt"); 
      std::vector&lt;entry&gt; v; // contains the reservations
      std::vector&lt;entry&gt; a; // contains the cancellations
      const int limit_total_weight = 10000;   // kg
      int total_weight = 0;                   // kg
      entry current;
      while (stream_in)
      {
          current = read_passenger(stream_in);
          if (total_weight + current.weight &gt;= limit_total_weight)
          {
              // push data (cancellations) to vector
              a.push_back(current);
          }
          else
          {
              total_weight = total_weight + current.weight;
              // push data (reservations) to vector
              v.push_back(current);
          }
      }
      reservations(v); // write reservations to file
      std::cout &lt;&lt; "Rest " &lt;&lt; limit_total_weight - total_weight &lt;&lt; "kg" &lt;&lt;std::endl;
      return 0;
  }
  </code></pre>