我如何获得地图< sting,int>从C ++到C# [英] How I can get map<sting, int> from C++ to C#
本文介绍了我如何获得地图< sting,int>从C ++到C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从dll获取地图c ++
C ++代码
I am trying to get map from dll c++
C++ code
extern "C" __declspec(dllexport) map<string, int> createMap(string &fileName) {
ifstream infile(fileName);
vector<string> bitsLine;
bool headerEnded = false;
string line;
int i = 0;
int length = 0;
while (getline(infile, line)) {
if (headerEnded) {
bitsLine = split(line, ',');
signalsMap.insert({ bitsLine.at(0), length });
}
else {
if (line.find("HEADER_END") != std::string::npos) {
headerEnded = true;
}
}
length = infile.tellg();
i++;
}
return signalsMap;
}
我的尝试:
C#代码
What I have tried:
C# code
Dictionary<string, int> x = createMap("C:/users/asalah/source/repos/WindowsFormsApp3/WindowsFormsApp3/RR_Test2_3.csv");
推荐答案
你最好的选择是使用C ++ / CLI
(并且可能直接填充字典,而不使用std :: map
。例如,请参阅 c ++ - Cpp / Cli将std :: map转换为.net字典 - Stack Overflow [ ^ ]。
Your best bet is usingC++/CLI
(and possibly directly fill the Dictionary, without using thestd::map
at all). See, for instance c++ - Cpp/Cli Convert std::map to .net dictionary - Stack Overflow[^].
您好,
我认为您基本上需要做的是使用STL / CLR将您的原生c ++容器映射到.Net包含。您可以在以下链接中找到一个很好的示例和有用的信息:
如何:从STL / CLR容器转换为.NET集合Microsoft Docs [ ^ ]
请注意:
适配器(STL / CLR)| Microsoft Docs [ ^ ]
如果它不起作用,请不要犹豫,然后我会尝试改进我的解决方案。
干杯,
AH
Hi,
I think basically what you need to do is to use STL/CLR to map your native c++ container into .Net contains. You can find a good example and useful information at the below link:
How to: Convert from a STL/CLR Container to a .NET Collection | Microsoft Docs[^]
For your attention:
adapter (STL/CLR) | Microsoft Docs[^]
Please do not hesitate to leave a comment if it didn`t work then I will try to improve my solution.
Cheers,
AH
这篇关于我如何获得地图< sting,int>从C ++到C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文