Visual Studio Character Error

Asked

Viewed 559 times

2

I cannot resolve a character error in Visual Studio.

Code 1:

#include "pch.h"
#include <iostream>
#include <cstdlib>
#include <clocale>
#include <Windows.h>

using namespace std;

int main()
{
    SetConsoleTitle("{ TEST }");
    system("color 0A");

    cout << "Ola Mundo\n";

    cout << "ÁÉÍÓÚÇ\n";

    setlocale(LC_ALL, "Portuguese");
    cout << "ÁÉÍÓÚÇ\n" << endl;

    setlocale(LC_ALL, "");
    wcout << L"ÁÉÍÓÚÇ" << endl;

    getchar();
    return 0;
}

Result Code 1: Print Código 1

Code 2:

#include "pch.h"
#include <iostream>
#include <Windows.h>

void SetTitle_lithe() {

    SetConsoleTitle("Process Memory Tools C++ - Family { CODE BUILDING }");
    system("color 0A");

    printf("\n");
    printf("       ██████╗ ██████╗ ██████╗ ███████╗    ██████╗ ██╗   ██╗██╗██╗     ██████╗ ██╗███╗   ██╗ ██████╗ \n");
    printf("      ██╔════╝██╔═══██╗██╔══██╗██╔════╝    ██╔══██╗██║   ██║██║██║     ██╔══██╗██║████╗  ██║██╔════╝ \n");
    printf("      ██║     ██║   ██║██║  ██║█████╗      ██████╔╝██║   ██║██║██║     ██║  ██║██║██╔██╗ ██║██║  ███╗\n");
    printf("      ██║     ██║   ██║██║  ██║██╔══╝      ██╔══██╗██║   ██║██║██║     ██║  ██║██║██║╚██╗██║██║   ██║\n");
    printf("      ╚██████╗╚██████╔╝██████╔╝███████╗    ██████╔╝╚██████╔╝██║███████╗██████╔╝██║██║ ╚████║╚██████╔╝\n");
    printf("       ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝    ╚═════╝  ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚═╝╚═╝  ╚═══╝ ╚═════╝ \n");
    printf("                            Process Memory Tools C++ - Family { CODE BUILDING }\n");
    printf("\n");
}

int main()
{
    SetTitle_lithe();
    printf(" O processo 'Game.exe' não está em execução, abra e tente novamente!");

    getchar();
    return 0;
}

Result Code 2: inserir a descrição da imagem aqui

The problem started occurring after I had formatted Windows. At this time Windows 10 is updated in the latest version as well as Visual Studio and Windows SDK. I have tried to downgrade the Windows 10 SDK but failed to solve the problem as well.

Result Code 2 - Previous to Windows Formatting: inserir a descrição da imagem aqui

How to solve this problem?

1 answer

1


Probably the "regional settings" of your Windows are not in English, and as you are making the setlocale call with the wrong parameter, you are unable to change the locale.

According to this Microsoft page the locale name for Portuguese is "Portuguese-Brazilian", not "Portuguese": https://docs.microsoft.com/en-us/cpp/c-runtime-library/language-strings?view=vs-2017

You can display the locale name after calling setlocale, as I did in the example below, to check if the locale has been changed.

Also, you should check your Windows settings for the language being used. I took a look here, and I found it very confusing...in fact I could not reproduce your problem, in my Windows works normally, and this answer is not really an answer, it is more a comment with suggestions...

#include <clocale>
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
  cout << "*\n";
  cout << "* antes do setlocale Portuguese\n";
  cout << "* Olá Mundo\n";
  cout << "* ÁÉÍÓÚÇ\n";

  // const char* locale = setlocale(LC_ALL, "Portuguese");
  const char* locale = setlocale(LC_ALL, "portuguese-brazilian");
  cout << "* locale is now [" << locale << "]\n";

  cout << "*\n";
  cout << "* após setlocale Portuguese\n";
  cout << "* Olá Mundo\n";
  cout << "* ÁÉÍÓÚÇ\n" << endl;

  locale = setlocale(LC_ALL, "");
  cout << "* locale is now [" << locale << "]\n";

  cout << "* após setlocale \"\"\n";
  cout << "* Olá Mundo\n";
  cout << "* ÁÉÍÓÚÇ" << endl;
  wcout << L"* ÁÉÍÓÚÇ" << endl;

  cout << "* pressione a tecla ENTER para terminar\n";
  getchar();
  return 0;
}                       

Browser other questions tagged

You are not signed in. Login or sign up in order to post.