//1.char*转string char* c ="abc"; string s(c); //2.const char*转string const char* c_s ="abc"; string s(c_s); //3.string转const char* string s ="abc"; const char* c_s = s.c_str(); //4.string转char* string s="abcde"; const int n=s.length(); char *c=new char[n+1]; strcpy(c,s.c_str()); //5.const char*转char* const char* cpc ="abc"; char* pc =newchar[100];//足够长 strcpy(pc,c);
时间: 2024-10-12 20:31:56