string与char*转换
string–>char*
#include <iostream>
#include <string>
using namespace std;
int main() {
std::string s = "hello world";
char c[20];//不能为char* c;或char* c=NULL;提示必须初始化;
strcpy(c, s.c_str());//strcpy(c,s.data());
cout << c << endl;
}//正常打印
#include <iostream>
#include <string>
using namespace std;
int main() {
std::string str = "hello world";
char* chr = const_cast<char*>(str.c_str());
cout << chr << endl;
}//正常打印
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "hello world";
char* chr = &str[0];
cout << chr << endl;
}//正常打印