title: How to sort vector of struct C++
body: <p>I'm trying to sort vector of <code>struct</code>, but it ends with error. I tried to do it according to C++ reference, but I don't know where the problem is. Could someone help me?</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  /*
   * 
   */
  struct reg{
      string name;
      string addr;
  };
  
  int main(int argc, char** argv) {
  
   vector &lt;reg&gt; a;
      reg newReg = { "John", "Street1"};
      a.push_back(newReg);
      reg newReg2 = { "Mike", "Street2"};
      a.push_back(newReg2);
      std::sort (a.begin(), a.end());  
  
  return 0;
  }
  </code></pre>