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

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

    string::c.str() returns a string of type const char * as seen here

    A quick fix: try casting printfunc(num,addr,(char *)data.str().c_str());

    While the above may work, it is undefined behaviour, and unsafe.

    Here's a nicer solution using templates:

    char * my_argument = const_cast ( ...c_str() );
    

提交回复
热议问题