Test to see if a file exists

I'm writing a program that takes two addresses, one of a source file and one of a destination to copy the file to. I'm wanting a way to test to see if the source even exists. As far as I know, if I use any fstream functions to read a file, it'll just create a new file if it doesnt exist. That's not what I'm wanting here. Any suggestions?
closed account (o3hC5Di1)
Hi there,

Can't give you an immediate answer, but here's some links to topics that cover the subject with plenty of suggestions:

http://www.cplusplus.com/forum/general/1796/
http://www.cplusplus.com/forum/general/71414/
http://www.cplusplus.com/forum/general/23392/

Hope that helps.

All the best,
NwN
Ah yes thank you! This gives me a few different ideas to try this out.
Try
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
	fstream f("test_file.txt");
	if(!f)
	{
        cout << "Error: ";
        return 1;
    }

    cout << "Success";
   return 0;
}

fstream doesn't create the file automatically.
Topic archived. No new replies allowed.