string - > char *: 方法1:(转成const char *) string s = "abcdeg"; const char *k = s.c_str(); 方法2: string s = "abcdefg"; char *data; int len = s.length(); data = (char *)malloc((len+1)*sizeof(char)); //len+1是因为字符串末尾还要加个\0 s.copy(data,len,0); char* -> string 直接赋值即可 char data[]="abcdefg"; string s=data;