const char* = char*
Char * can be converted to const char. It cannot be sent.
Remove the const attribute as follows:
string str = "aaa";char* p =const_cast<char*>(str.c_str());printf("%s",p);Const_cast is used to discard the const declaration of a variable, but cannot change the const attribute of the object to which the variable points. That is, const_cast is used for objects originally not Const. If it is used for objects originally const, the results are unpredictable (this situation is not specified in C ++ ), please note that the above underlined "variable" vs "object" must be understood by myself. In general, const_cast is used in this situation: When the const pointer (variable) points to a non-const object and the programmer confirms this (the object to which it points is not a const, use the const_cast operator to discard the const modifier of the variable to obtain a non-const pointer. For details, see section 15.4.2.1 of the c ++ programming language (Special Edition.