Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't use accents with string in C++

So I can set the accents with SetConsoleOutputCP(1252) or locale::global(locale"FR-fr") but I can’t use it with Strings. Seems like its one or the other. I can output text with accents or I can output the string with accents not both any ideas?

The code bellow can be used to reproduce the problem. Simply add: locale::global(locale"FR-fr") or SetConsoleOutputCP(1252)

#include <iostream>
#include <string>
#include <windows.h>
using namespace std;

int main()
{
   string mot;
   cout << "Inscrivez un mot avec des accents (é ou è): ";
   cin >> mot;
   cout << mot;
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I suggest that you set both the input and output code pages:

SetConsoleCP(1252);       // input
SetConsoleOutputCP(1252); // output
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading