Program to delete a line given the line number from a file
Given a file and a line number n, the task is to delete nth line from the given text file.
Suppose the initial content of myfile.txt is :
After Deletion of Line 2 the content would be :
1) Open the source file in input mode and read it character by character.
2) Open another file in output mode and place contents in the file character by character.
3) Rename the other file to the source file.
line_no = 1;
(line_no != n)
ofs << c;
n = 3;
Note: Run this code offline IDE keep text file name
as "a.txt" in same folder
Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.