Problem with accents

I have problems displaying words with accents in the console.
Example :

 cout << "Première lettre: " << Response[0];

And the console shows that :


I hope you can help me.

At this point, it would be best to avoid using accents. If it bothers you to omit accents when writing in your native language, then consider writing input/output text in English.

In order to be able to use accents, you would need to learn why and how to use Unicode strings in your application, which would be complicated at this point.

In case you just want to experiment and see it working with accents, below are some steps you can try. However, please do not follow along the course with these modifications, because these kinds of changes can make your application crash mysteriously later if you don’t know exactly what you are doing. So, if you are feeling adventurous, first make a backup of your current main.cpp, then try out the following:

  • Add the following lines to the top of your source file:

    #include <fcntl.h>
    #include <io.h>
  • Add the following lines as the very first lines of your main() function:

    _setmode(_fileno(stdout), _O_U16TEXT);
    _setmode(_fileno(stdin), _O_U16TEXT);
  • Use the “Find and Replace” tool to make the following replacements:

    cin --> wcin
    cout --> wcout
    string --> wstring
  • Add the character ‘L’ immediately before every literal string in your code, right before the opening quote. For example:

    "Première lettre: " --> L"Première lettre: "

As you can see, even these changes seem like a lot to make accents work. So, really, for now, it’s better to try to move on without them.

1 Like

Thanks a lot for your answer.

Privacy & Terms