title: C++ Error "failure: locale::facet::_S_create_c_locale name not valid" when running program from command line
body: <p>I seem to have a problem with locales in C++. When I run my programm from within Eclipse, it all works fine. However, when I try to run from the command line, I keep getting this error: </p>
  
  <p>failure: locale::facet::_S_create_c_locale name not valid</p>
  
  <p>This is the code that triggers the error: </p>
  
  <pre><code>// Set up UTF8 file stream
  string fileName = "./sz.txt";
  wifstream inFileStream;
  
  try {
      setlocale(LC_ALL, "");
      inFileStream.open(fileName.c_str());
      inFileStream.imbue(locale(""));
      if(!inFileStream) {
      return EXIT_FAILURE;
      }
  }
  catch (const std::exception &amp;exc) {
      wcout &lt;&lt; "Error while trying to create UTF8 file stream." &lt;&lt; endl;
      std::cerr &lt;&lt; exc.what() &lt;&lt; endl;
      if( inFileStream.is_open() )
          inFileStream.close();
  
      return EXIT_FAILURE;
  }
  </code></pre>
  
  <p>The output of "locale" gives the following: </p>
  
  <pre><code>LANG="de_DE.UTF-8"
  LC_COLLATE="de_DE.UTF-8"
  LC_CTYPE="de_DE.UTF-8"
  LC_MESSAGES="de_DE.UTF-8"
  LC_MONETARY="de_DE.UTF-8"
  LC_NUMERIC="de_DE.UTF-8"
  LC_TIME="de_DE.UTF-8"
  LC_ALL="de_DE.UTF-8"
  </code></pre>
  
  <p>I have also tried to use "de_DE.UTF-8" as the locale string instead of "" (the way it should be actually), but this gives me the same error.</p>
  
  <p>And strangely enough, the program works fine when run from within Eclipse. I am using g++ to compile from the command line with the following version: </p>
  
  <p>Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
  Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
  Target: x86_64-apple-darwin12.4.0
  Thread model: posix</p>
  
  <p>Any idea what might be wrong here? </p>
  
  <p>Cheers, </p>
  
  <p>Martin</p>