0

I'm trying to open some C++ source files from a programming textbook companion CD, but Dev-C++ throws me this message:

No mapping for the Unicode character exists in the target multi-byte code page Address : 0x0014206D

It seems there's not support for characters in my language (Brazilian Portuguese), like accute accents. If I convert the encoding to UTF-8 with Notepad++, Dev-C++ can then open and compile the source without errors, but doesn't render the non US/ANSI characters correctly. In the provided source file, "salário" is output as "sal├írio" on the program.

Here's the source file:

https://drive.google.com/file/d/1MltK2dLY_ElUIMuWM8xlO8i_fr6yEdns/view?usp=sharing

edit: I'm using version 6.3, downloaded from GitHub

ksio89
  • 1
  • 1
  • You forgot to write a question. – user253751 Apr 26 '22 at 15:08
  • @user253751 Maybe not, if you're going to be picky about it, but the OP's problem seems clear enough to me. Anyway ksio, maybe a bit tangential but [this](https://royqh.net/devcpp-en/) might be of interest, especially since it talks about _adding_ UTF-8 support. Seems that DevC++ is not quite dead yet. And if you want `iconv` for Windows, there's some info [here](https://superuser.com/questions/290593/how-to-convert-character-encodings-on-windows), although `Notepad++` might be enough. Oh, I see Marek has deleted his answer so bye-bye `iconv`. Not sure why. – Paul Sanders Apr 26 '22 at 15:16
  • But I'm sure he's right. Move over to the Red Panda stuff if you need to and convert your source file(s) to UTF-8. – Paul Sanders Apr 26 '22 at 15:20
  • 1
    Some versions of DevC++ were used by the ancients to hunt Dinosaurs. Make sure the DevC++ you are using is one of the more recent ones. – user4581301 Apr 26 '22 at 15:26
  • Try add `setlocale(LC_CTYPE, "");` at begging of `main`. – Marek R Apr 26 '22 at 15:26
  • How do you view the output? Also please don't post links to things like google drive. Post a [mcve] directly in the question. – n. m. could be an AI Apr 26 '22 at 17:28
  • Notepad++ will probably export your file as UTF-8, but your default code page is probably cp850 (or maybe cp860). You can try running your program from a `cmd` window after typing a command `chcp 65001`. Does this produce desired output? Alternatively, you may want to ditch UTF-8 and use cp850, Re-export your source from Notepad++ choosing cp850 as the encoding (you need to dig in the encoding submenu), recompile, and rerun from Dev C++. Does this produce desired output? – n. m. could be an AI Apr 26 '22 at 17:39
  • @PaulSanders thank you for the suggestion, this fork is able to open the source files, and autodetects the encoding as ANSI (Windows-1252). However, ever after converting it to UTF-8, it still doesn't render non-ANSI characters correctly. – ksio89 Apr 26 '22 at 19:12
  • @user4581301 I'm using version 6.3, after Embarcadero took over the project – ksio89 Apr 26 '22 at 19:13
  • @n.1.8e9-where's-my-sharem. I run it on CMD, but it still doesn't produce correct characters after typing that command before running the program. – ksio89 Apr 26 '22 at 19:14
  • @ksio89 Can you save your source files as 'UTF-8 with BOM'? If so, I would expect that Red Panda will be able to figure out that the files are encoded as UTF-8 automatically. – Paul Sanders Apr 26 '22 at 19:15
  • Yes, but still won't output correct characters, even if I write the code from scratch. Anyway, at least I can open now open the source files with Red Panda, I think that's good enough, as I pretty must just need to inspect the source code of the solutions to the questions. Thank you very much for the help. – ksio89 Apr 26 '22 at 20:36
  • Does this answer your question? [Output unicode strings in Windows console app](https://stackoverflow.com/questions/2492077/output-unicode-strings-in-windows-console-app) – phuclv Apr 27 '22 at 03:15
  • in Windows currently you should use UTF-16 by default. If you want to use UTF-8 you need some compile options: [What is the Windows equivalent for en_US.UTF-8 locale?](https://stackoverflow.com/a/63454192/995714) – phuclv Apr 27 '22 at 03:17
  • @MarekR gave the right answer, thank you. Doing a further search, I found a [post](https://pt.stackoverflow.com/questions/300379/como-imprimir-caracteres-utf-8-na-console-c) here, that instructed to declare library `` and use `setlocale( LC_ALL, "" );`, and now it's outputting UTF-8 characters from current locale correctly. – ksio89 May 03 '22 at 03:55

0 Answers0