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

前端 未结 3 1171
你的背包
你的背包 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:45

    Well, data.str().c_str() yields a char const* but your function Printfunc() wants to have char*s. Based on the name, it doesn't change the arguments but merely prints them and/or uses them to name a file, in which case you should probably fix your declaration to be

    void Printfunc(int a, char const* loc, char const* stream)
    

    The alternative might be to turn the char const* into a char* but fixing the declaration is preferable:

    Printfunc(num, addr, const_cast(data.str().c_str()));
    

提交回复
热议问题