understanding - warning: deprecated conversion

Learning C++ after 25 year hiatus from any programming.

Have inserted the following line in my program:

char *incomingfile = "historical.txt"

Upon building the file I am getting the following message:

warning: deprecated conversion from string constant to 'char*'

I really not sure what the warning means and what I would need to do to avoid the warning.

Help would be appreciated.

Thank you.

Have a Great Day,
Jim
The type of a string literal in C++ is const char*
String literals are actually immutable arrays of characters that the compiler pre-allocates and initializes statically somewhere. In other words they are mostly equivalent to const char[]. But for some archaic historical reasons, which I can not recall, the C language permitted assigning string literals to non-const-qualified char pointers, like yours. Trying to modify something inside this string with such pointer will not result in syntax error, but is undefined behavior nonetheless. In fact, it may glitch badly on some systems, where the strings may be loaded in some kind of read-only memory. That's why the compiler does you a favor and warns you to use const char pointer instead.

Regards
Topic archived. No new replies allowed.