CLR system::string^转std::string

MSDN文档:https://docs.microsoft.com/en-us/cpp/dotnet/overview-of-marshaling-in-cpp?redirectedfrom=MSDN&view=vs-2019

使用实例

#include 
#include 

using namespace msclr::interop;
using namespace System::Runtime::InteropServices;



stdAlgoManage gAlgoManage;

long VisionApm::Apm_CS::GetAlgoList(List<String^>^% AlgoList1D)
{
	vector<string> AlgoList;
	stdAlgoList::GetAlgoList(AlgoList);
	
	for (vector<string>::iterator iter = AlgoList.begin(); iter != AlgoList.end(); iter++)
	{
		String^ tmpMStr = marshal_as<String^>(iter->c_str());
		AlgoList1D->Add(tmpMStr);
	}
	
	return 0;
}

long VisionApm::Apm_CS::AddAlgoFun(String^ funName)
{
	char* pchar = (char*)Marshal::StringToHGlobalAnsi(funName).ToPointer();
	std::string tmpFunName=marshal_as<std::string>(funName);
	gAlgoManage.AddAlgoFun(tmpFunName);
	Marshal::FreeHGlobal(IntPtr((void*)pchar));
	return 0;
}

你可能感兴趣的:(MFC)