vendredi 3 novembre 2017

C++ string literal warning

I am learning C++. In the below program

str1 is not giving any warning and then why str2 giving following warning?

As far as I know, str1 and str2 shall stores the address of first char of string.

warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     char *str2="world";


#include <iostream>
using namespace std;

int main() 
{
    char str1[]="hello";
    char *str2="world";
    cout<<str1<<endl;
    cout<<str2<<endl;
}

Aucun commentaire:

Enregistrer un commentaire