I have 2 versions of a console program that deals with accented text, both inputted by the user and hardcoded in the program, but the behavior seems strange to me. The following code shows the issue :
Version 1 :
int main(){
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
string str1 = "héhé";
cout << str1 << endl;
string str2;
cin >> str2;
cout << str2 << endl;
}
output :
héhé //str1
héhé //input str2
h h //str2
Version 2 :
int main(){
string str1 = "héhé";
cout << str1 << endl;
string str2;
cin >> str2;
cout << str2 << endl;
}
output :
h├®h├® //str1
héhé //input str2
héhé //str2
I would have expected the text to be displayed properly with utf-8 codepage..
Is there a way to display both strings correctly ? Hopefully without using wstring since the entire program is already pretty complex.
Thanks a lot !