如何转换常量为wchar_t *到System ::字符串? [英] How do i convert const wchar_t* to System::String?

查看:254
本文介绍了如何转换常量为wchar_t *到System ::字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的SHA1(wchar_t的*)转换成一个正常的字符串^为了使用它在一个特定的功能。有任何想法吗?我试图谷歌,但所有的结果是我的问题正好相反。 :\

I need to convert my SHA1 (wchar_t*) to a normal String^ in order to use it in a certain function. Any ideas? I tried Google but all the results were the exact opposite of my question. :\

注:我使用C ++ .NET框架和Windows窗体应用程序

NOTE: I am using C++.NET framework and Windows Forms Applications

推荐答案

使用构造函数;像这样的:

Use the constructor; like this:

const wchar_t* const pStr1 = ...;
System::String^ const str1 = gcnew System::String(pStr1);

const char* const pStr2 = ...;
System::String^ const str2 = gcnew System::String(pStr2);

如果您使用的是标准的C ++字符串类(的std :: wstring的的std ::字符串) ,你可以用 c_str()方法的指针。您的code,则可能是

If you're using the standard C++ string classes (std::wstring or std::string), you can get a pointer with the c_str() method. Your code then might be

const std::wstring const std_str1 = ...;
System::String^ const str1 = gcnew System::String(std_str1.c_str());

请参阅<一href="http://msdn.microsoft.com/en-us/library/6y4za026.aspx?cs-save-lang=1&cs-lang=cpp#$c$c-snippet-1"相对=nofollow> System.String 和广泛讨论的这里

这篇关于如何转换常量为wchar_t *到System ::字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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