将string直接转换成const char *类型,一个是.c_str(),一个是data成员函数。
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
string s1 = "hello world!";
const char *p1 = s1.c_str();
const char *p2 = s1.data();
printf("%s %s\n",p1,p2);
cout <<p1 << " " << p2 << endl;
return 0;
}