Is there a way to check file existence. I know it tells you how in the tutorials, but that way doesn't work for me.
And I am using Visual C++ .net
Printable View
Is there a way to check file existence. I know it tells you how in the tutorials, but that way doesn't work for me.
And I am using Visual C++ .net
>>Is there a way to check file existence.
Yes.
Post your code that "doesn't work". Maybe you did something wrong. Anyways, one way to check is to simply open the file in read mode (with no-create), if it works, the file exists, if not, it doesn't
#include <io.h>
that is code from the c tutorial at http://www.cprogramming.com/tutorial/lesson14.html which I adapted to be used in my program, which the compiler returned the error of access not being a valid functionCode:if(access(argv[1], 00)) //access returns 0 if the file can be accessed
{ //under the specified method (00)
cout<<"File does not exist"; //because it checks file existence
return 0;
}
try this .
This checks for errors when opening a file.Code:if (!=infile) // if not equal to name of file (ifstream infile)
{
cerr << "cant open";
exit (-1);
}
// then your code follows