Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i convert const wchar_t* to System::String?

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. :\

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

like image 556
FreelanceCoder Avatar asked Mar 29 '13 02:03

FreelanceCoder


1 Answers

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);

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());

See System.String and extensive discussion here.

like image 187
Ðаn Avatar answered Sep 19 '22 00:09

Ðаn