vector转换为char*[]

int ReqSubMarketData(std::vector& vecInstrucment)
{
	char** destination = new char*[vecInstrucment.size() + 1];
	MakeCString(vecInstrucment, destination);
        // param char* ppD[], int nSize
	SubscribeMarketData(destination, static_cast(vecInstrucment.size()));
	
	// 释放资源
	for (int n = 0; n < static_cast(vecInstrucment.size()); n++)
	{
		delete[] (destination[n]);
	}

	delete[] destination;
	destination = NULL;

	return ERR_OK;
}

void MakeCString(const std::vector& source, char** destination)
{
	// 注意释放内存
	for (int n = 0; n < static_cast(source.size()); ++n)
	{
		destination[n] = new char[32];
		destination[n][31] = '\0';
		strncpy(destination[n], source[n].c_str(), 31);
	}

	//destination[source.size()] = NULL;
}

你可能感兴趣的:(c/c++)