Deprecated conversion from string literal to 'char*'

后端 未结 3 1825
无人及你
无人及你 2020-12-01 02:13

I have a program which declares an array of strings like this:

char *colors[4] = {\"red\", \"orange\", \"yellow\", \"blue\"};

But I get the

3条回答
  •  情书的邮戳
    2020-12-01 02:32

    "red", "orange", "yellow", "blue"
    

    these are constant string. Creating a non-const pointer to a constant string is wrong, hence the warning. At the moment you are getting a warning, but it should be an error since it is deprecated in c++03, and forbiden in c++11.

提交回复
热议问题