title: How to check if file exists in C++ in a portable way?
body: <p>Currently I use this code to check if file exists on <code>Windows</code> and <code>POSIX</code>-compatible OSes (Linux, Android, MacOS, iOS, BlackBerry 10):</p>
  
  <pre><code>bool FileExist( const std::string&amp; Name )
  {
  #ifdef OS_WINDOWS
      struct _stat buf;
      int Result = _stat( Name.c_str(), &amp;buf );
  #else
      struct stat buf;
      int Result = stat( Name.c_str(), &amp;buf );
  #endif
      return Result == 0;
  }
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li><p>Does this code have any pitfalls? (maybe an OS where it cannot be compiled)</p></li>
  <li><p>Is it possible to do it in a truly portable way using only C/C++ standard library?</p></li>
  <li><p>How to improve it? Looking for canonical example.</p></li>
  </ol>