如何在c ++中将“PWSTR”转换为“System :: String ^”

时间:2013-05-15 18:00:14

标签: c++-cli

我想知道如何将“PWSTR”转换为“System :: String ^”

   My code snippet follows here...

   array<System::String^>^ nsRecords;

   try
   {
     nsRecordCount = dns.query(ipAddressString);
     nsRecords = gcnew array<System::String^>(nsRecordCount);

     for(int nsRecord = 0; nsRecord < nsRecordCount; nsRecord++)
     {
   DNS_PTR_DATA record  = dns.getNth(nsRecord);
 // below line of code causing error C2440: '=' :  
     //cannot convert from 'PWSTR' to 'System::String ^'
       nsRecords[nsRecord] = record.pNameHost; 
     }

   }

感谢您的帮助!

谢谢,   拉马尼

1 个答案:

答案 0 :(得分:1)

gcnew String()应该足够了。顺便说一句,这是一个C ++ / CLI问题,而不是c ++ 11。