Const char * To char *, remove the const attribute

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.