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

651 Views Asked by At

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);
2

There are 2 best solutions below

0
Jeaninez - MSFT On BEST ANSWER

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.

1
g19fanatic On

It seems like the code is working as is for me on godbolt.org

https://godbolt.org/z/nGz3hcG3c

Not needing to change parameters to const or anything else...

I do get warnings using gcc but not msvc

This looks like a compiler issue on your end, not with msvc19 I wonder if your VS install has a setting that treats warnings as errors? Check out https://stackoverflow.com/a/66485736/496405 to disable this option.