title: C++ reports file does not exist, even though it does
body: <p>My Windows C++ program reports a file does not exist, even though it does.</p>
  <p>I confirmed the file exists both with CMD and with Windows Explorer.</p>
  <p>CMD test:</p>
  <pre>
  >dir C:\Windows\System32\winevt\Logs\Microsoft-Windows-WMI-Activity%4Trace.etl
   Volume in drive C has no label.
   Volume Serial Number is DCCE-93FA
  
   Directory of C:\Windows\System32\winevt\Logs
  
  03/22/2022  02:20 PM         1,048,576 Microsoft-Windows-WMI-Activity%4Trace.etl
                 1 File(s)      1,048,576 bytes
                 0 Dir(s)  1,571,579,912,192 bytes free
  </pre>
  <p>Windows Explorer test:</p>
  <p><a href="https://i.stack.imgur.com/Rl6Bp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rl6Bp.png" alt="enter image description here" /></a></p>
  <p>My C++ code:</p>
  <pre><code>std::ifstream file;
  const char* path = &quot;C:\\Windows\\System32\\winevt\\Logs\\Microsoft-Windows-WMI-Activity%4Trace.etl&quot;;
  file.open(path);
  if (file.is_open()) {
      std::wcout &lt;&lt; path &lt;&lt; &quot; exists\n&quot;;
  } else {
      std::wcout &lt;&lt; &quot;Failed to open &quot; &lt;&lt; path &lt;&lt; &quot;\n&quot;;
      perror(&quot;Error&quot;);
  }
  file.close();
  </code></pre>
  <p>C++ program's output:</p>
  <pre>
  Failed to open C:\Windows\System32\winevt\Logs\Microsoft-Windows-WMI-Activity%4Trace.etl
  Error: No such file or directory
  </pre>
  <p>I ran my C++ program as Administrator, so there shouldn't be any permissions problem. (Plus, if there was a permissions problem, I would expect a different error message.)</p>
  <p>I'm looking for any ideas of how to fix my program so it can open the file.</p>