Search code examples
c++character-encodingvisual-studio-2019const-char

Can not covert from 'const char*' to 'char*' in VS19, although earlier could


I bought a Surface Go 2 today, and installed Visual Studio 2019. I loaded my project, that successfully compiled on my previous PC, also in VS19.

The first problem that I noticed is that the VS editor displays Unicode characters (Cyrillic) in my .cpp files as hieroglyphs:

card->NewTextW(L"Çàãðóçêà", ...

Instead of:

card->NewTextW(L"Загрузка",

Then I tried to compile the project, but got more then a hundred errors, and all of them were about the compiler can't convert from const wchar/char * to wchar/char *, although, I repeat, that earlier, in another PC, everything compiled successfully. This error appears to almost all types of strings, and for strings with wrong encoding, like mentioned above, and without.

Specific example of error

card->NewTextW(L"Çàãðóçêà", 3, r.right/2-50, r.bottom / 2 - 350 / 2 - 80 + 350 + 60, 10, 20, RGB(0, 0, 0));
card->NewText("eng-string", 4, r.right/2-50, r.bottom / 2 - 350 / 2 - 80 + 350 + 60, 10, 20, RGB(0, 0, 0));

Where card is a pointer to an object of interface virtual class ICard:

class ICard
{
public:
...
virtual void NewTextW(wchar_t *text, int id, int x, int y, int divid, int j, COLORREF col) = 0;
virtual void NewText(char *text, int id, int x, int y, int divid, int j, COLORREF col) = 0;
...
}card*;

Specific example of no error

MessageBoxA(NULL, "aga", "uogou", MB_OK);

Solution

  • Cannot covert from 'const char*' to 'char*' in VS19, although earlier version could

    According to the doc: /permissive- (Standards conformance)

    By default, the /permissive- option is set in new projects created by Visual Studio 2017 version 15.5 and later versions. It's not set by default in earlier versions. When the option is set, the compiler generates diagnostic errors or warnings when non-standard language constructs are detected in your code. These constructs include some common bugs in pre-C++11 code.

    As far as I'm concerned, this is a good explanation of why this error did not appear in the earlier version.