将C#字符串转换为c ++字符串的正确方法 [英] Proper way to convert a C# string to a c++ string

查看:146
本文介绍了将C#字符串转换为c ++字符串的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我知道。网上已经多次询问过这个问题,但是我正在寻找一种避免[declspec]事情的方法。


因为我已经制作了一个.dll的C ++项目并添加了该.dll文件作为我的C#项目的引用。现在,如果我诚实,我不知道如何将c#字符串传递给c ++字符串。我已经尝试了很多东西,但现在直到
才能工作。


C#代码:

 [.. 。] 
if(dlg.ShowDialog()== DialogResult.OK)
{
strToSend = dlg.SelectedPath;
obj.SetString(strToSend);

}
[...]

C ++代码:

 

[...]

void OpenCvWrapper :: SetString(string s)
{
//用字符串

}做的东西

[...]

还有其他办法吗?



谢谢,


Andries



解决方案

你好,


这对你有帮助吗?
https://stackoverflow.com/questions/1300718/c-net- convert-systemstring-to-stdstring


此致,Guido


Hi everyone,

I know. This question has been asked several times on the Net but I'm looking for a way to avoid the [declspec] thing.

Because I have made a .dll of my C++ project and added that .dll file as a reference to my C# project. Now If I'm honest I don't quite know how to pass over a c# string to a c++ string. I have tried alot of things but it's not working until now.

C# code:

[...]
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    strToSend = dlg.SelectedPath;
                    obj.SetString(strToSend);

                }
[...]

C++ code:

[...]

void OpenCvWrapper::SetString(string s) { //do stuff with string }

[...]

Is there another way?

Thanks,

Andries

解决方案

Hello,

does this help you ? https://stackoverflow.com/questions/1300718/c-net-convert-systemstring-to-stdstring

Regards, Guido


这篇关于将C#字符串转换为c ++字符串的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆