A
A
AntonIgin2016-03-20 16:45:46
IDE
AntonIgin, 2016-03-20 16:45:46

How to normally change the encoding in Visual Studio?

The problem is this. I write in Russian - when compiling, krakozyabra climbs. I put Cyrillic 866 - everything works fine. I save, close, open, I see this:

#include <iostream>
using namespace std;

int main()
{
  cout << "Hello, World!" <<"\n" << "1. dfапЏаЁўҐв" "\n";
  cin.ignore();
}

When compiled, krakozyabry become ordinary letters.
The Russian letters added at the second launch will be hieroglyphs, and changing the encoding no longer helps: it says that some Unicode characters were not saved in the code page. In general, some kind of conflict.
What to do?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Makarov, 2016-03-20
@Nipheris

Working version for working with UTF-8 strings (2015 studio). Don't forget to resave the source in UTF-8 encoding.

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

int main()
{
  SetConsoleOutputCP(CP_UTF8);
  auto message = u8"Тест тест";
  wprintf(L"%S", message);
    return 0;
}

For the future:
1) with Unicode and UTF-8 in particular, Windows has some hemorrhoids for a number of historical reasons (in particular, due to the fact that WinAPI's native Unicode encoding is UTF-16); you just need to be able to solve this problem (if you don’t want to develop on Linux);
2) it does not negate the fact that you need to know well what you are doing in general. VS is a tool for the job, especially for C++ projects, and there are certain things you need to understand in order to use it. It's me in general, so that you change your approach.

A
Alexander Ananiev, 2016-03-20
@SaNNy32

You have some problems with the installed studio. Try reinstalling it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question