std::string convert to const char *
inline char * getCharPtr(string &str){
char *cha = new char[str->size() + 1];
memcpy(cha,str->c_str(),str->size() + 1);
const char *p = cha; //point to this new allocated memory
return p;
}
本文介绍了一个C++函数,该函数用于将std::string类型转换为const char*指针。通过内存分配和复制操作实现,适用于需要将字符串转换为C风格字符串的场景。
3215

被折叠的 条评论
为什么被折叠?



