'getting error as deprecated conversion from string constant to 'char*' [-Wwrite-strings]

I'm getting error as deprecated conversion from string constant to 'char*' [-Wwrite-strings] at initgraph() function

// C Implementation for drawing circle 
#include <graphics.h> 

//driver code 
int main() 
{ 
    int gd = DETECT, gm; 

    initgraph(&gd, &gm, ""); //here I'm getting an error of string

    circle(250, 200, 50); 

    getch(); 

    closegraph(); 

    return 0; 
} 


Solution 1:[1]

"" is a c-style string literal whose type is const char[1] and could convert to const char* implicitly. Implicit conversion to char* is not allowed since C++11.

In C, string literals are of type char[], and can be assigned directly to a (non-const) char*. C++03 allowed it as well (but deprecated it, as literals are const in C++). C++11 no longer allows such assignments without a cast.

Making initgraph taking const char* is the best. Otherwise you have to perform explicit conversion with const_cast; but note that attempting to modify a string literal results in undefined behavior. If initgraph would do, then you shouldn't pass a string literal.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1