0

I'm just starting to learn C++ and I wanted to know how to display special characters like in this french sentence "J'aime le café" and I don't want to have to put something like \uefdddf. I want to be able to display the char with this code:

#include <iostream>
using namespace std;

int main() {
    printf("J'aime le café");
}

I want it to display this French sentence J'aime le café in the terminal, not J'aime le cafÚ.

I've searched the web for several answers but haven't found what I'm looking for. I hope you can help me. I'm using windows 10 and MinGW.

BatteTarte
  • 61
  • 7
  • 4
    Unfortunately, printing/reading non-ASCII heavily depends on your operating system, compiler, the exact way you compile and run the program. Sometimes OS settings as well (e.g. "locale"). – yeputons Aug 03 '23 at 22:58
  • 2
    Have you heard of the C++ I/O streams? Like [`std::cout` and `std::wcout`](https://en.cppreference.com/w/cpp/io/cout)? – Thomas Matthews Aug 03 '23 at 23:00
  • If you have a strong objection to C++ I/O streams, you should review the C language [*wide* I/O streams](https://en.cppreference.com/w/c/io/fwprintf). – Thomas Matthews Aug 03 '23 at 23:03
  • 2
    You can use `u8` ([UTF-8 string literals](https://en.cppreference.com/w/cpp/language/string_literal)). – Jesper Juhl Aug 03 '23 at 23:03
  • 7
    Proper internationalization and locale-related topics and issues are a surprisingly advanced topic in C++, and suffers from rather poor, and cumbersome support. Thankfully, there's plenty to learn about C++ for someone who's just starting to learn it, and there won't be any shortage of core C++ fundamental topics to be covered, before delving into these tangled subjects... – Sam Varshavchik Aug 03 '23 at 23:11
  • @JesperJuhl The trick is "what to do next" though. As Sam points out, there's plenty of info out there, but it's certainly not an easy subject. – Ted Lyngmo Aug 03 '23 at 23:15
  • 1
    [Some wisdom on the wonderful world you're starting to explore](https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/). – user4581301 Aug 03 '23 at 23:38
  • @SamVarshavchik This comment doesn't answer my question – BatteTarte Aug 03 '23 at 23:42
  • 3
    It does, it's just a tactful way of pointing out that before tackling thorny issues of internationalization and localization, someone who's learning C++ will learn the following, first: classes, templates, pointers, references, inheritance, multiple inheritance, polymorphism, overloading, templates, variadic templates, type traits, metaprogramming, concepts, and many more core C++ fundamentals, before getting into boutique specialized domains, like internationalization. – Sam Varshavchik Aug 03 '23 at 23:53
  • Does this answer your question? [How to print Unicode character in C++](https://stackoverflow.com/questions/12015571/how-to-print-unicode-character-in-c) – Jan Schultke Aug 04 '23 at 09:02

0 Answers0