std::string 转换为 const* char,方式如下:
std::string str;
const char * c = str.c_str();
如果需要转换为一个可变char,做法如下:
std::string str;
char * writable = new char[str.size() + 1];
std::copy(str.begin(), str.end(), writable);
writable[str.size()] = '\0'; // don't forget the terminating 0
// don't forget to free the string after finished using it
delete[] writable;
需要说明的是,上面的这个方法并不是非常安全,在新的调用和被删除之前有可能会导致内存泄露。解决的方法有两个,使用boost::scoped_array或者std::vector采用copy的方式进行重新构建。