cygwin64においてのwstringとwcout(文字化けなど)

g++ なら文字化けせずに日本語が出力される。

#include <iostream>

using namespace std;

int main() {

  // 成功
  setlocale(LC_ALL, ""); // or setlocale(LC_ALL, "ja_JP.UTF-8");

  wchar_t const *s = L"あいうえお";

  wcout << wcslen(s) << " : " << s << endl;

  // $ g++ -std=c++11 -Wall test.cpp;./a
  // $ 5 : あいうえお
}
#include <iostream>

using namespace std;

int main() {

  setlocale(LC_ALL, ""); // or setlocale(LC_ALL, "ja_JP.UTF-8");

  wstring s = L"あいうえお";

  wcout << s.length() << " : " << s << endl;

  // $ g++ -std=c++11 -Wall test.cpp;./a
  // $ 5 : あいうえお
}

x86_64-w64-mingw32-g++ ならコンパイルは出来るが正しく出力されない。

#include <iostream>

using namespace std;

int main() {

  setlocale(LC_ALL, ""); // or setlocale(LC_ALL, "ja_JP.UTF-8");

  wchar_t const *s = L"あいうえお";

  wcout << wcslen(s) << " : " << s << endl;


  // $ x86_64-w64-mingw32-g++ -std=c++11 -Wall test.cpp;./a
  // $ 5 : ******(文字化け)
}
#include <iostream>

using namespace std;

int main() {

  setlocale(LC_ALL, ""); // or setlocale(LC_ALL, "ja_JP.UTF-8");

  wstring s = L"あいうえお";

  wcout << s.length() << " : " << s << endl;

  // $ x86_64-w64-mingw32-g++ -std=c++11 -Wall test.cpp;./a
  // $ 5 : ******(文字化け)
}