Saving textfiles

Im trying to get the user to choose whether he/she wants to
save a text document in a file, I would first check whether a file already exists
and would ask the user to overwrite or no, if yes then I would save that particular document, Is there a code that exist for such tasks......thanks

Last edited on
You can test whether a file exists or not this way:

1
2
3
4
5
6
7
8
9
10
ifstream file;
file.open("input.txt");
if (file)
{
    cout << "The file exists.";
}
else
{
    cout << "The file does not exist.";
}
Thanks,
and if the file exists, and the user wants to overwrite the file
then I would just use the code for creating the text file which is to be saved.....right??

Oh, and could you point me, as to how one would open a text file using a function....thanks
Last edited on
Yes. Try it yourself and tell us how it goes.
Topic archived. No new replies allowed.