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
This is a discussion on File detection within the C++ Programming forums, part of the General Programming Boards category; Is there a way to check file existence. I know it tells you how in the tutorials, but that way ...
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.
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
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
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
#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
C++ Rules!!!!
------------
Microsoft Visual Studio .NET Enterprise