title: I have a list of STL vectors and I want to sort them by the first element of each vector
body: <p>I have a list of vectors from STL. They have different lengths and I want to sort them by the first element of each vector. For example, I have the vectors: 4 <strong>4</strong> 5 6 10, 1 <strong>8</strong>, 2 <strong>2</strong> 3 and 3 <strong>1</strong> 7 9. The first number is the size of each vector and it is followed by the vector's elements. I want to display the vectors in a file, sorted by the first element. In this example, my vectors should display in this order: 3 <strong>1</strong> 7 9, 2 <strong>2</strong> 3, 4 <strong>4</strong> 5 6 10 and 1 <strong>8</strong>.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>ofstream fout ("retele.out");
  fout &lt;&lt; T &lt;&lt; '\n';
  for (i=1; i&lt;=T; i++)
  {
      fout &lt;&lt; sol[i].size() &lt;&lt; ' ';
      sort(sol[i].begin(),sol[i].end());
      for (j=0; j&lt;sol[i].size(); j++)
          fout &lt;&lt; sol[i][j] &lt;&lt; ' ';
      fout &lt;&lt; '\n';
  }
  fout.close();
  </code></pre>
  
  <p>"T" is the number of vectors. The "sort" function is for sorting each vector, and I also need an another sort for sorting the vectors as I just described.</p>