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!!

Recommended Answers

All 4 Replies

  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.

I'm not going to give you speciffic code, but some useful links:
ifstream for opening files for reading.
ofstream for opening files for writing.
stringstream for tokenizing parts of the input stream.
getline for getting an entire line from a file, or from any other input stream.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.