vector<string>转换为char*[]

来源:互联网 发布:黑米软件官方 编辑:程序博客网 时间:2024/05/17 04:00
int ReqSubMarketData(std::vector<std::string>& vecInstrucment){char** destination = new char*[vecInstrucment.size() + 1];MakeCString(vecInstrucment, destination);        // param char* ppD[], int nSizeSubscribeMarketData(destination, static_cast<int>(vecInstrucment.size()));// 释放资源for (int n = 0; n < static_cast<int>(vecInstrucment.size()); n++){delete[] (destination[n]);}delete[] destination;destination = NULL;return ERR_OK;}void MakeCString(const std::vector<std::string>& source, char** destination){// 注意释放内存for (int n = 0; n < static_cast<int>(source.size()); ++n){destination[n] = new char[32];destination[n][31] = '\0';strncpy(destination[n], source[n].c_str(), 31);}//destination[source.size()] = NULL;}

0 0
原创粉丝点击