0
#include <iostream>                           
#include <clocale>                            
#include <string>                             

int main() {                                  
    std::setlocale(LC_ALL, "en_US.utf8");     
    std::wstring str(L"Τὴ γλῶσσα μοῦ ἔδωσαν");
    std::wcout << str << std::endl;           
    std::wcerr << str << std::endl;           
}         

This produces no output on the terminal.

How can I get it to produce UTF-8 output? I figure that ought to be something supported by C++.

I am aware of the utfcpp library, which I am using, but the question is specifically whether there is a stdlib way to print out UTF8.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364

1 Answers1

0

I got it by following this.

std::setlocale(LC_ALL, ""); is the magic incantation.

This worked on my trivial test program. However my full program still completely fails at printing out wstrings.

That is fine (well, no, it is still somewhat alarming), I will avoid relying on stdlib, and do it myself with the help of utfcpp library, which is excellent. This way I can use cout and cerr for everything and all will be well.

Community
  • 1
  • 1
Steven Lu
  • 41,389
  • 58
  • 210
  • 364