const char* && string && String^ 类型转换

时间:2022-03-16 15:19:25

const char* && string && String^ 类型转换

const char* ---> string

const char * cw= "kkkkkkkkkk";

string sw = cw;

string ---> const char*

using namespace std;

string s = "kkkkk";

const char* cc = s.data();

const char* ---String^

using namespace System::Runtime::InteropServices;

const char* cc = "dddddddddd";

System::String^ cmStr = gcnew System::String(cc);

const char* iconData = "sjhfksssssl";

String^ temp = String(iconData).ToString();

String^ ---> const char*

using namespace System::Runtime::InteropServices;

String^ className = "hhhh";

const char* ts = (char*)(Marshal::StringToHGlobalAnsi(className)).ToPointer();

String^ ---> string

using namespace System::Runtime::InteropServices;

String^ className = "hhhh";

const char* ts = (char*)(Marshal::StringToHGlobalAnsi(className)).ToPointer();

string sw = ts;

string ---> String^ string sw = "shkhk"; const char* cw = sw.data(); String^ temp = String(cw).ToString();