title: deleting line in linux text file with C++
body: <p>i need help in how i should write a code for doing a delete line using c++ in linux. what i have in the text file is listed below</p>
  
  <blockquote>
    <p>description:amount:date<br>
    electricity bill:100:25jan2015<br>
    telephone bill:100:25jan2015<br>
    telephone bill:50:25jan2015</p>
  </blockquote>
  
  <p>i want to do it so that when the user selects option b to remove the expense that the user input and to prevent the program from deleting duplicate data the user will have to input the amount and date. thank you.</p>
  
  <p>and the temp.txt is used to store what was not deleted before being renamed to Expense.txt so if telephone bill value 100 was removed it would become</p>
  
  <blockquote>
    <p>electricity bill:100:25jan2015<br>
    telephonebill:50:25jan2015</p>
  </blockquote>
  
  <pre><code>void deleteexpensesdata(string&amp; expense, string&amp; texpense, double&amp; amount,  string&amp; date){
  int check, x=0;
  ifstream Expenses("Expense.txt");
  ofstream temp("temp.txt");
  cout &lt;&lt; "\n";
  cout &lt;&lt; "Enter Type of Expense you wish to remove" &lt;&lt; endl;
  cin &gt;&gt; texpense;
  
  while(Expenses &gt;&gt; expense &gt;&gt; amount &gt;&gt; date){
      if(texpense!=expense){//if there are expenses with different name, input their data into temp file
          temp &lt;&lt; expense &lt;&lt; ":" &lt;&lt; amount &lt;&lt; ":" &lt;&lt; date &lt;&lt;endl;
      }
      if(texpense==expense){// if user entered correct name, x=1 for later output message that the user data has been deleted
         x=1; 
      }
  }
  
  Expenses.clear();
  Expenses.seekg(0, ios::beg);
  Expenses.close();
  temp.close();
  remove("Expense.txt");
  rename("temp.txt","Expense.txt");
  if(x==0){//x was set to 0 at start, so if it didn't change, it means there is error
      cout &lt;&lt; "Remove of Expense failed" &lt;&lt; endl;
  }
  else{//if x is not = 0 then remove is successful
      cout &lt;&lt; "Expenses has been removed" &lt;&lt; endl;
  }
   }
  </code></pre>
  
  <p>the code that calls the function is below </p>
  
  <pre><code>        cout &lt;&lt; "Remove Expense.\n";
          deleteexpensesdata(expense, texpense, amount, date);
          cout &lt;&lt; "Expense Date has been delete. \n" &lt;&lt; endl;
          cin.ignore();
          cin.get();
  </code></pre>