title: C++: Which is the best method of checking for file existence on windows platform
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3828835/how-can-we-check-if-a-file-exists-or-not-using-win32-program">How can we check if a file Exists or not using Win32 program?</a>  </p>
  </blockquote>
  
  
  
  <p>Which is the best method for checking for file existence:</p>
  
  <p>Option1:</p>
  
  <pre><code>GetFileAttributes("C:\\MyFile.txt"); // from winbase.h
  if(0xffffffff == GetFileAttributes("C:\\MyFile.txt"))
  {
      //File not found
  }
  </code></pre>
  
  <p>Option2:</p>
  
  <pre><code>std::string fileName("C:\\MyFile.txt" );
  ifstream fin( fileName.c_str() );
  
  if( fin.fail() )
  {
      //File not found
  }
  </code></pre>
  
  <p>Also if you think option 1 is the better method, can you tell me how to define <code>0xffffffff</code> as a constant (I don't want to use #define)</p>
  
  <p>Thanks</p>