sort names by their age
<p>i want so sort names by their ages</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

struct Person{
 std::string name;
 int age;
};

struct by_age{
  bool operator() (Person  const &amp;a,Person const &amp;b){
   return a.age&gt;b.age;    
  }
};

int main(){
 vector&lt;Person&gt;people;
  for (int i=0;i&lt;4;i++){
   cin&gt;&gt;people[i].age&gt;&gt;people[i].name;
  }

  sort(people.begin(),people.end(),by_age());
   for (int i=0;i&lt;4;i++){
    cout&lt;&lt;people[i].name&lt;&lt;people[i].age&lt;&lt;" ";
   }    
 return 0;
}
</code></pre>

<p>but this code has many bugs please help
look at this site</p>

<p><a href="http://stackoverflow.com/questions/1723066/c-stl-custom-sorting-one-vector-based-on-contents-of-another">http://stackoverflow.com/questions/1723066/c-stl-custom-sorting-one-vector-based-on-contents-of-another</a></p>
