Hi!
i'm new in c++, i have some problems with files...
-first of all i want to know that how i can save a file with the name that program gives it? for example i run the program and type"file1" then save the file with name "file1.txt". whatever i give it...

-second i want to know how to search a text file for a specific string like "1892"?

-third:how can i delete somthing specific in my file,for example just a couple of lines or just one line,how can i delete it?

that's all for now... thanks a lot!!

  1. use a char variable

    char filename[255];
    getline(cin,filename);
    ifstream in(filename);

  2. read each line of the file. When a line is read search it for the desired text. In c++ you can use std::string's find() method.

  3. You have to completely rewrite the file, leaving out the line you want deleted.

for 2 and 3 would you please give me code? i'm new in c++...
thanks so much for your response.

for 2 and 3 would you please give me code? i'm new in c++

No. You give it a try then post the code you have written and ask questions about what you don't understand. Asking me to do your work for you will not teach you a thing.

This article has been dead for over six months. Start a new discussion instead.