2011-12-20 37 views

回答

2

this link at Microsoft

void MarshalString (String^s, string& os) { 
    using namespace Runtime::InteropServices; 
    const char* chars = 
     (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer(); 
    os = chars; 
    Marshal::FreeHGlobal(IntPtr((void*)chars)); 
} 

int main() { 
    string a = "test"; 
    String^c = gcnew String("abcd"); 
    cout << a << endl; 
    MarshalString(c, a); 
    cout << a << endl; 
} 
+0

感谢你非常:) – 2011-12-20 21:32:24

相关问题