#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
string str = "hello world!";
int len = str.length();
char *p;
p = (char *)malloc((len)*sizeof(char));
str.copy(p,len,0);
printf("%s\n",p);
cout << p << endl;
return 0;
}
运行结果如下: