## conversion between string, char*, const char*Back

#### string

• to char*
``````string s = "abc";

/* new a char pointer and point to a char instance with the size */
char* c;
const int len = s.length();
c = new char[len + 1];

/* use strcpy to copy string to the char instance */
strcpy(c, s.c_str());
``````
• to const char*
``````string s= "abc";

const char* c_s = s.c_str();
``````

#### const char*

• to char*
``````char* c;
const char* c_s = "abc";

const int len = strlen(c_s) + 1;
strcpy(c, c_s);
``````
• to string
``````const char* c_s = "abc";
string s(c_s);
``````

#### char*

• to const char*
``````const char* c_s = "abc";
char* c = c_s
``````
• to string
``````char* c = "abc";
string s(c);
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.7896099,"math_prob":0.9907201,"size":922,"snap":"2022-27-2022-33","text_gpt3_token_len":254,"char_repetition_ratio":0.20152505,"word_repetition_ratio":0.017857144,"special_character_ratio":0.31344903,"punctuation_ratio":0.15053764,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98480135,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-07T17:08:09Z\",\"WARC-Record-ID\":\"<urn:uuid:4212a194-656f-4dfc-aee1-ac0384ea1f63>\",\"Content-Length\":\"498345\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f89e93c7-268f-4d6f-9d67-015ec9f7192b>\",\"WARC-Concurrent-To\":\"<urn:uuid:6fd94586-b163-476d-9912-98dce02d1b93>\",\"WARC-IP-Address\":\"185.199.110.153\",\"WARC-Target-URI\":\"https://wiki.aleen42.com/Programming/c/conversion_of_str/conversion_of_str.html\",\"WARC-Payload-Digest\":\"sha1:Z72HB2QFLH7WFU2BXHGDJS6GESCHWCXH\",\"WARC-Block-Digest\":\"sha1:A67WNGMWJ6TESZ7LJWA2AXIPD3LGIW3W\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656104495692.77_warc_CC-MAIN-20220707154329-20220707184329-00367.warc.gz\"}"}