String,const char*,char* between the transitions

Source: Internet
Author: User

1. String to const char*

string s = "abc";

Const char* c_s = S.c_str ();

2. Const char* Turn string

Directly assign the value can

Const char* c_s = "abc";

string s (c_s);

3. String Transfer char*

string s = "abc";

char* C;

const int len = S.length ();

c = new Char[len+1];

strcpy (C,s.c_str ());

4. char* Turn string

char* c = "abc";

string s (c);

5. Const char* Turn char*

Const char* CPC = "ABC";

char* pc = new char[100];//long enough

strcpy (PC,CPC);

6. char* to const char*

Directly assign the value can

char* PC = "ABC";

Const char* CPC = PC;

String,const char*,char* between the transitions

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.