将char [] 转换成System::String
char name[10]=”abcdefg”;
System::String^ str_name;
str_name = gcnew String(name);
将System::String 转换成char *
#include “stdafx.h”
#include <iostream>
#include <string>
#include <vcclr.h>
using System::String;
void stoc(System::String^ str,char *nstring)
{
pin_ptr <const wchar_t> wch = PtrToStringChars(str);
// Convert to a char*
size_t origsize = wcslen(wch) + 1;
size_t convertedChars = 0;
wcstombs_s(&convertedChars, nstring, origsize, wch, _TRUNCATE);
}
前面有些头文件是不必要的
0 条评论
沙发空缺中,还不快抢~