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;
}

>Solution :

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

SetConsoleCP(1252);       // input
SetConsoleOutputCP(1252); // output

Leave a Reply