12 Jun 2011

.NETstring^到char*的转换

.NETstring^到char*的转换 .net中都是string^类型,如果要使用旧版c++的char*,可以如下转换 // convert from string to char*
char *str2chars(String ^s)
{
char *pHead, *pInd;
pHead = pInd = new char[s->Length+1];
for (int i=0;i<s->Length;++i)
*pInd++ = s[i];
*pInd = '\0';
return pHead;
}

No comments :

Post a Comment