How to show accented characters in Visual Studio 2017 using C ++?

1

Good afternoon,

I asked this question a long time ago, but it was bad so I deleted it and I'm redoing it in more detail.

My problem is this: When I use accent in Visual Studio it returns strange characters. This only happens when I compile using Visual Studio, when I use Code :: Blocks the output is normal.

Here is the code:

#include "stdafx.h" //essa linha somente no Visual Studio
#include <iostream>
#include <cstdlib>
#include <clocale>
using namespace std;

int main()
{
    setlocale(LC_ALL, "Portuguese");
    cout << "ÁÉÍÓÚ" << endl;
    system("pause");
    return 0;
}

Here are the exits:

Visual Studio 2017:

à à à à à à Ã

Code :: Blocks 16.01:

AIOUS

I have tried to use setlocale I tried to use the chcp 850, 65001 and 1200 command like this: system("chcp xxx" ) where xxx is the code.

I changed the font to Lucida Consoles, it also did not work.

I tried to change the source and the executable to UTF-8 via command line with / source-charset: utf-8 / execution-charset: utf-8 and did not work.

You have an option to change the registry but this is ridiculous. What's more, Code :: Blocks works quietly, just by adding setlocale .

Additional information:

OS: Windows 10 Home

I've already used it in setlocale "", "English", and more ...

Any suggestions / ideas? Thank you.

Att;

    
asked by anonymous 15.10.2017 / 20:54

1 answer

1

The call of setlocale( LC_ALL, "" ); (with the second blank parameter), causes the default locale of the program to be set according to the variables of its environment, which certainly uses the encoding UTF-8 as default:

#include <iostream>
#include <locale>

int main(void)
{
    setlocale( LC_ALL, "" );

    std::wcout  <<  L"ÁÉÍÓÚ"  <<  std::endl;
}

The UTF-8 encoding covers practically all existing alphabets, making the language specification an unnecessary detail.

#include <iostream>
#include <locale>


int main(){

    setlocale( LC_ALL, "" );

    std::wstring ch = L"你好世界";
    std::wstring gk = L"γειά σου κόσμος";
    std::wstring jp = L"こんにちは世界";
    std::wstring ko = L"여보세요 세계";
    std::wstring pt = L"Olá mundo!";
    std::wstring ru = L"Здравствулте мир!";

    std::wcout << L"Chinês    : " << ch << std::endl;
    std::wcout << L"Grego     : " << gk << std::endl;
    std::wcout << L"Japonês   : " << jp << std::endl;
    std::wcout << L"Coreano   : " << ko << std::endl;
    std::wcout << L"Português : " << pt << std::endl;
    std::wcout << L"Russo     : " << ru << std::endl;

}

Output:

Chinês    : 你好世界
Grego     : γειά σου κόσμος
Japonês   : こんにちは世界
Coreano   : 여보세요 세계
Português : Olá mundo!
Russo     : Здравствулте мир!
    
16.10.2017 / 22:11