One ,string->char*

1, take string turn char*, have access to string Provided c_str() perhaps data()
function . among c_str() Function returns a '\0' Array of characters at the end , and data() Return string content only , It has no terminator '\0'.

2,const char* c_str();

c_str() Function returns a pointer C Pointer to the string , The pointer points to the memory contents and string
identical . because c Language not supported string type , So in order to c++ compatible C character string , Provided c_str() Function to implement the conversion . Be sure to use it strcpy() Function c_str();
c_str() A temporary pointer is returned , It cannot be operated on .
char ch[20]; string s="123456"; strcpy(ch,s.c_str());
c_str() with char* Form return string Contains a string

If a function requires char* parameter , have access to c_str() method :
 
string str="123456"; printf("%s",str.c_str()); const char* p=a.data(); const
char* p=a.c_str(); char* p=const_cast<char*>(a_str());
Two ,char*-->string

Direct assignment
string s; char* p ="hello"; s = p;
Three ,string-->char[]
string pp = "dagah"; char p[8]; int i; for( i=0;i<pp.length();i++) p[i] =
pp[i]; p[i] = '\0'; printf("%s\n",p); cout<<p;
Four ,char[] turn string

It can be assigned directly .

Technology
©2020 ioDraw All rights reserved
Swing actual combat Understanding closure about vue in el-date-picker type=daterange The problem of date not echoing Ubuntu 18.04 swap Partition expansion Snake code --c Language Edition visual c++6.0 open 【Golang Basic series 10 】Go language On conditional sentences ifString class —— summary ,String The nature of , Memory resolution , Commonly used APIAdobe Illustrator Publish native support Apple Silicon Test version of the software study java My first class antd table sort