invalid conversion from 'const char*' to 'char*'

前端 未结 3 1178
你的背包
你的背包 2020-12-14 14:44

Have a code as shown below. I have problem passing the arguments.

stringstream data;
char *addr=NULL;
strcpy(addr,ret         


        
3条回答
  •  不知归路
    2020-12-14 15:23

    First of all this code snippet

    char *addr=NULL;
    strcpy(addr,retstring().c_str());
    

    is invalid because you did not allocate memory where you are going to copy retstring().c_str().

    As for the error message then it is clear enough. The type of expression data.str().c_str() is const char * but the third parameter of the function is declared as char *. You may not assign an object of type const char * to an object of type char *. Either the function should define the third parameter as const char * if it does not change the object pointed by the third parameter or you may not pass argument of type const char *.

提交回复
热议问题