>> So please could some one point me in the right direction.
Prelude gave you the steps already. Is there something specific you are having trouble implementing?
>> So please could some one point me in the right direction.
Prelude gave you the steps already. Is there something specific you are having trouble implementing?
Hello everybody
I am new to c++ and I am trying to find a way to delete a line of text from a text file.
My program is writing to the file no problem and I can read it back in and display it in a DOS console screen. But one of the options I need is to find a line of text and then delete that line from the file.
Is C++ capable of doing such a thing?
plus how do you search a text file for a specific word or words?
Thank you for any help you may provide.
>Is C++ capable of doing such a thing?
No. I say no because when people ask if C++ is "capable" of doing something, they want a simple function like:
Can you do it? Yes. Does C++ give you the tools to do it? Yes. Is everything you could ever want wrapped up in a nice little package with a bow? Of course not. To delete a line from a file, the common solution is to do something like read the file into a vector, delete the line you want to delete, and then overwrite the file with your changes because most files don't support record-oriented operations like deletion of a line.Code:#include <magic> bool delete_line_from_file ( fstream& file, int line_number );
>plus how do you search a text file for a specific word or words?
The string class has a slew of find member functions that will help you pick out pieces.
My best code is written with the delete key.
C++ is capable of doing almost anything. (Unless you want to do something unrealistic)Is C++ capable of doing such a thing?
"The Internet treats censorship as damage and routes around it." - John Gilmore
Ok then I understand C++ is capable of doing such a task
And I understand that it will not be easy to do.
I know it won't be an easy thing to do.
If it was just a simple one line command then why would I be asking
a forum how to do it.
So please could some one point me in the right direction.
* Read in a file to some variable, a vector of strings was suggested.
* Decide what you want to be taken out from the file, ie a line number or something
* Delete that from memory (from the variable).
* Save the variable's contents to the same file name.