title: How to set the std::locale with gcc under cygwin?
body: <p>I'm trying to make a simple program to enumerate the files on my disks, but I'm stuck at the great UTF frontier. </p>
  
  <p>I'm using boost::recursive_directory_iterator to enumerate the files. That's works great, but Windows is set to "french canada" and many files and directories have french characters (likes é, è, ç). These filenames are not displayed correctly on the screen and I'm using wcout. I see a '▒' instead of the acute chars. Even boost::filesystem::ifstream is unable to open these files.</p>
  
  <p>I tried to add "std::locale::global(std::locale(""))", but at first that only thrown an exception. I have found that when LANG is set to "" while executing the program, the previous command does not throw any more, but it only set the "C" locale instead of being the one use by the OS (which I expect to be "fr_CA.UTF-8" or "fr_CA.ISO8859-1"). Any other value for LANG bring the exception back...</p>
  
  <p>What must be done to have a cygwin gcc program usable in an i18n world?</p>
  
  <p>I have write this to test various locale ID:</p>
  
  <pre><code>#include &lt;iomanip&gt;
  #include &lt;iostream&gt;
  #include &lt;locale&gt;
  
  using namespace std;
  
  void tryLocale(string ID)
  {
      try{
          cout &lt;&lt; "Trying " &lt;&lt; std::setw(18) &lt;&lt; std::left &lt;&lt; "\"" + ID + "\" ";
  
          std::locale Loc(ID.c_str());
          cout &lt;&lt; "OK (" &lt;&lt; Loc.name() &lt;&lt; ")" &lt;&lt; endl;
      }catch(...){
          cout &lt;&lt; "FAIL" &lt;&lt; endl;
      }
  }
  
  const char *Locales[] = { "", "fr", "fr_CA", "fr_CA.UTF-8", "fr_CA.ISO8859-1", "C", 0};
  
  int main()
  {
      cout &lt;&lt; "Classic = " &lt;&lt; std::locale::classic().name() &lt;&lt; endl &lt;&lt; endl;
  
      int i = 0;
      do
      { tryLocale(Locales[i]);
      } while(Locales[++i]);
  
      return 0;
  }
  </code></pre>
  
  <p>And that gives me this output (without any LANG or LC_ALL):</p>
  
  <pre><code>Classic = C
  
  Trying ""                FAIL
  Trying "fr"              FAIL
  Trying "fr_CA"           FAIL
  Trying "fr_CA.UTF-8"     FAIL
  Trying "fr_CA.ISO8859-1" FAIL
  </code></pre>
  
  <p>With LANG set to "", the first "trying" becomes</p>
  
  <pre><code>Trying ""                OK (C)
  </code></pre>
  
  <p>The exception thrown print this:</p>
  
  <pre><code>terminate called after throwing an instance of 'std::runtime_error'
    what():  locale::facet::_S_create_c_locale name not valid
  </code></pre>