title: Delete specific line from file
body: <p>I'm trying to delete a specific line by id from a file in C++ and here is my code:</p>
  
  <pre><code>void deleteRow()
  {
      ifstream inDb("files/students.dat", ios::in);
      if(!inDb)
      {
          cerr &lt;&lt; "File could no be opened!\n";
      }
  
      cout &lt;&lt; countRowsOfDb() &lt;&lt; " records." &lt;&lt; endl;
  
      Student *studentsArray[countRowsOfDb()];
  
      int n = 0;
  
      while(inDb &gt;&gt; id &gt;&gt; name &gt;&gt; grade &gt;&gt; points &gt;&gt; type)
      {
          studentsArray[n] = new Student(id, name, grade, points, type);
          n++;
      }
  
      inDb.close();
  
      for(int i = 0; i &lt; countRowsOfDb(); i++)
      {
          cout &lt;&lt; studentsArray[i]-&gt;id &lt;&lt; " " &lt;&lt; studentsArray[i]-&gt;name &lt;&lt; " " &lt;&lt; studentsArray[i]-&gt;grade &lt;&lt; " "
               &lt;&lt; studentsArray[i]-&gt;points &lt;&lt; " " &lt;&lt; studentsArray[i]-&gt;type &lt;&lt; "\n";
      }
  
      cout &lt;&lt; "\nWhich one you would like to delete? Enter an id: ";
  
      string term;
      cin &gt;&gt; term;
  
      ofstream outDb("files/students.dat", ios::out);
      if(!outDb)
      {
          cerr &lt;&lt; "File could no be opened!\n";
      }
  
  
      for(int i = 0; i &lt; countRowsOfDb(); i++)
      {
          if(studentsArray[i]-&gt;id != term)
          {
                  outDb &lt;&lt; studentsArray[i]-&gt;id &lt;&lt; " " &lt;&lt; studentsArray[i]-&gt;name &lt;&lt; " " &lt;&lt; studentsArray[i]-&gt;grade &lt;&lt; " "
                        &lt;&lt; studentsArray[i]-&gt;points &lt;&lt; " " &lt;&lt; studentsArray[i]-&gt;type &lt;&lt; "\n";
          }
      }
  
      outDb.close();
  
      cout &lt;&lt; "\nObject deleted!\n";
  }
  </code></pre>
  
  <p>I create a input file stream and then get all the rows, make it array of objects and show them on the screen then ask which one to delete by typing an id, and when I type the id, I'm trying to put all these elements of the array only without the element with same id, but it don't works, after that there is nothing in the file. Any ideas?</p>