0

I wrote a program using printfs() of "é" or "à" compiling with MinGW 4.9.1, I was using setlocale(LC_CTYPE, "fra"); to display these characters and it worked well

However when I compile the same program with MinGW 11.2 the accents are displayed this way : "é" "Ã" I tried with setlocale(LC_ALL, ""); and it doesn't work either

Does anyone have a solution?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
BeauCloud
  • 11
  • 5
  • The problem is with the Console used. Either yours is badly configured or can not accept UTF8 encoded chars. – Jean-Baptiste Yunès Jun 19 '23 at 13:02
  • 2
    Please [edit] your question and show a [mre]. What is the encoding of the source file? UTF8? How exactly do you run the program? In a CMD window? In a bash window? – Bodo Jun 19 '23 at 13:03
  • Questions seeking debugging help should generally provide a [mre] of the problem, which includes a function `main` and all `#include` directives. This allows other people to easily test your program, by simply using copy&paste. – Andreas Wenzel Jun 19 '23 at 13:05
  • 1
    @GuillaumeRacicot • it's not experimental support anymore (as mentioned in phuclv's update). It's primetime now. Still needs to be explicitly enabled. – Eljay Jun 19 '23 at 13:08
  • AFAIK MinGW is not very good with locale support. Some time ago I wrote answer for MSVC: https://stackoverflow.com/a/67819605/1387438 which could be helpful to address this issue. – Marek R Jun 19 '23 at 13:09
  • 1
    Thanks for your fast answers all, I tested `setlocale(LC_ALL, ".utf8")` and it worked :) – BeauCloud Jun 19 '23 at 13:13
  • @BeauCloud Adding "SOLVED" to the question is not how SO works. If there is an answer that accurately answers your problem, accept it. You can also choose to retract the question alltogether, by deleting it. – bitmask Jun 19 '23 at 13:18

1 Answers1

2

On Windows, you must explicitly set utf-8 as opposed to other platforms like Linux:

std::setlocale(LC_ALL, ".utf8")

Windows assume code pages in its locale configuration unless the program or the user selects it. Doing this activates windows support for utf-8 in the console.

Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141