Accentuation in C++ Visualstudiocode

Asked

Viewed 78 times

1

I’m trying to use the accent in c++ but in the output the text continues without formatting I’m using the visual studio code.

#include <iostream>
#include <locale.h>

int main ()
{   
    setlocale(LC_ALL, "portuguese");
    int NumVidas = 5;
    int Pontuacao = 1350;

    std::cout << "Inicio de jogo\n" << std::endl;
    std::cout << "Numero de vidas: "<< NumVidas << std::endl;
    std::cout << "Pontuação: " << Pontuacao << "\n";

    NumVidas -= 1;
    Pontuacao -= 350; 

    std::cout << "\nNumero de vidas: "<< NumVidas << std::endl;
    std::cout << "Pontuação: " << Pontuacao << "\n";
    system("PAUSE");
}
  • Use "en" as locale. Test the return of setlocale() to see if the locale has been accepted. Run locale -a on your machine to see the list of locales if you are using Linux or even Windows if you have for example git installed.

2 answers

0

For those who go through the same problem in the future, I solved as follows in VSCODE:

I clicked in the lower right corner where you have UTF-8 and clicked on Reopen with Encondig and selected Western(ISO 8859-1) iso88591.
Remembering that you need to have compiled the code at least once. Soon after it will "format your code" and then you need to rewrite the words with the accents again.

To put the ISO 8859-1 by default you need to enter File > Preferences > Settings and in seaching type encoding and in Files: Enconding select the Western (ISO 8859-1).

Remembering that I am using Visual Studio Code and, I believe, in other Ides like Visual Studio does not need this process.

-1

  1. Press Windows + R and execute the command prompt.
  2. Type the command: cmd.exe /k chcp 65001.
  3. Run your program.

Browser other questions tagged

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