title: System locales and non-unicode programs
body: <p>I have a file in local d drive: d:\système.gz ( This file is generated in different region. Note the è. )</p>
  
  <p>I am trying to open this file using fopen using non-unicode executable. The following code works when System Locale for non-unicode program is set to "English(United States)".</p>
  
  <p>If I change this locale to "Japanese(Japan)" ( under Region Settings ) then fopen fails.</p>
  
  <p>This is how memory looks like for string 'système.gz':</p>
  
  <p>1: English(United States)</p>
  
  <pre><code>73 79 73 74 e8 6d 65 2e 67 7a
  </code></pre>
  
  <p>2: Japanese(Japan)</p>
  
  <pre><code>73 79 73 74 65 6d 65 2e 67 7a
  </code></pre>
  
  <p>How to handle this situation correctly? Do I have to invoke some API to set the locale in my code?</p>
  
  <pre><code>std::string path = "d:";
  
  for (auto &amp; p : fs::directory_iterator(path))
  {       
      std::string fName = p.path().filename().string();
      std::string ext = p.path().extension().string();
  
      if (ext == ".gz")
      {
          std::string drive = "d:\\" ;
          std::string fullPath = drive + fName;
          const char * strPath = fullPath.c_str();
          FILE * fp = fopen(strPath, "rb");
          if (!fp)
          {
              printf("\nNot found\n");
          }
          fclose(fp);
      }
  }
  </code></pre>
  
  <p>If I use:</p>
  
  <pre><code>p.path().filename().u8string()
  </code></pre>
  
  <p>Then memory changes to:(but fopen will still fail)</p>
  
  <pre><code>73 79 73 74 c3 a8 6d 65 2e 67 7a
  </code></pre>