Search code examples
c++c++17visual-studio-2019

Conversion from string literal loses const qualifier


error C2664: 'void add_log(char *,...)': cannot convert argument 1 from 'const char [33]' to 'char *'

message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)

I restarted my computer and now my project stopped being able to be built. I've looked everywhere that had the similar problems but can no longer build this project with any changes to the project.

Using -> ISO C++17 Standard (/std:c++17)

Character Set -> Use Multi-Byte Character Set

I don't understand what happened in a span of a few minutes for this to just completely break my project when I was compiling multiple times this morning.


Solution

  • As of today, all I had to do was add a const before anything that I use a char* for. This was used with VS2019 using std:c++17 and Multi-Byte Character Set.

    The original code:

    void add_log(char* format, ...)
    

    The new code

    void add_log(const char* format, ...)