c++ - How to delete a specific row in a text file using fstream -


Good day! My problem is that I should remove an entire specific line in my text file. But instead, I'm just changing it with white space. Actually, I do not know how to delete the line. Here's my code:

  fstream fs ("FoodList.txt"); // charPos here is the position of the file where I should start deleting Fs.seekp (charPos); // I loop 100 times because I'm sure every line is 100 characters (int i = 0; i & lt; i ++) {// what i really want to do, full line fs & lt ; & Lt; ""; }  

My text file will look like this: Before:

  Apple Carrot Cherry  

(If I select charPos = 3 ):

  apple of banana cherry  

By the way, I have already updated The part has been made. I can edit the specific lines, thank any kind of gratitude. :)

The easiest way to read files is by writing a temporary file, leaving the selected line And move the temporary file to the original one.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -