Checking if a file exits already

Started by
12 comments, last by Ziphnor 21 years, 10 months ago
quote:Original post by Ziphnor
Well, there could be other reasons for the failure to open the file, and i would like to be able to differentiate between failure because it didnt exists and failure for other reasons(ie, "real" error).


Like all streams (at least all that I know of), fstreams have methods like bad() and fail() to check for read/write errors.

quote:
The other reason i just dont try to open it, is that the most open file methods seems create the file if it doesnt exist(and then i would have to check file size to see if it had been created previously).

But the ifstream idea seems good, i guess the ifstream open method wouldnt create the file(that would be kind of silly, wouldnt it?)


You''re right. If you try to open a non-exsistent file with ifstream, it will not create the file.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
Advertisement
Try this from MSDN: the _access() function.
"after many years of singularity, i'm still searching on the event horizon"
But isnt the _access function win32 only? (the game in question is target towards windows but i see no reason to rely on the win32 API if i can use standard C++ calls instead).
quote:Original post by Ziphnor
i see no reason to rely on the win32 API if i can use standard C++ calls instead

There is no Standard C++ means of telling if a file exists.

This topic is closed to new replies.

Advertisement