Thread: File detection

  1. #1
    Registered User
    Join Date
    Nov 2002

    Question File detection

    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

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    >>Is there a way to check file existence.

    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    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]

  4. #4
    Registered User
    Join Date
    Nov 2002
    #include <io.h>
    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;
    that is code from the c tutorial at which I adapted to be used in my program, which the compiler returned the error of access not being a valid function

  5. #5
    Registered User
    Join Date
    Jun 2002
    try this .
    if (!=infile) // if not equal to name of file (ifstream infile) 
    cerr << "cant open";
    exit (-1);
    // then your code follows
    This checks for errors when opening a file.
    C++ Rules!!!!
    Microsoft Visual Studio .NET Enterprise

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  4. me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM