相关疑难解决方法(0)

如何将wchar_t*转换为std :: string?

我改变了我的类使用std :: string(基于我在这里得到的答案,但是我有一个函数返回wchar_t*.如何将它转换为std :: string?

我试过这个:

std::string test = args.OptionArg();
Run Code Online (Sandbox Code Playgroud)

但它说错误C2440:'初始化':无法从'wchar_t*'转换为'std :: basic_string <_Elem,_Traits,_Ax>'

c++ string wchar-t stdstring

30
推荐指数
5
解决办法
5万
查看次数

将字符串转换为 char* 到字符串 (C# -&gt; C -&gt; C++)

我正在开发带有 C 包装器的 C++ DLL,以便能够在不同的语言上使用它。目前,我也在 C# 中开发一个插件,它调用我的 DLL。

\n\n

我想要的是将字符串(文件的路径)作为 DLL 的参数传递,以便能够在我的 DLL 上使用它。

\n\n

C#

\n\n
[DllImport(DllName, CallingConvention = DllCallingConvention)]\npublic static extern IntPtr AllocateHandle(string filename);\n
Run Code Online (Sandbox Code Playgroud)\n\n

C 包装纸

\n\n
LPVOID SAMPLEDLL_API CALLCONV_API AllocateHandle(char* filename);\n
Run Code Online (Sandbox Code Playgroud)\n\n

C++ 类构造函数

\n\n
CustomData::CustomData(char* filename)\n{\n    _filename = filename; // string _filename;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我将 _filename 保存在文件上时(因为我没有找到使用 DLL 上的断点进行调试的方法),我有类似\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c\xc3\x8c0\xc3\xa0\xc3\x97. 我尝试了不同的解决方案将 char* 转换为字符串,但结果仍然相同。

\n\n

预先感谢您的帮助。

\n

c c# c++ string type-conversion

5
推荐指数
1
解决办法
1377
查看次数

标签 统计

c++ ×2

string ×2

c ×1

c# ×1

stdstring ×1

type-conversion ×1

wchar-t ×1