/* IDONT KNOW HOW TO DELETE a LINE FROM THE TEXTFILE.*/
You want to delete a line from the textfile that you are reading ? This is very tricky. When you read the file line by line, the file pointer is advancing forward to be ready to read the next line. If you want to delete the previous line that is read, you need to rewind your file pointer back.
There are fseek, ftell, rewind, fgetpos, fsetpos etc calls but still it is very tricky. Usually for such file-centric operations, I turn to shell scripts or Perl. I recommend Perl for it's ease in file io manipulation :)
The simplest answer in C++ is to simply load the file into a std::deque <std::string>, delete the Nth item, and then overwrite the file.
The other standard option is to copy the file, line by line, to a new file, making the desired changes as you go. Once done, delete the original file and rename the new file as the original.
The other standard option is to copy the file, line by line, to a new file, making the desired changes as you go. Once done, delete the original file and rename the new file as the original.
-- i've tried it but it deletes all the contents of the old file. i can.t copy it line by line. here's the code..
can you help me please?
I can't follow your code, where is the label again? (goto is evil, you can easily avoid it with loops and functions calls)
I don't see where do you write to the file either.
Is trapsearch() relevant? What does it do?