2012-12-05 93 views
1

我在C++中有一個std :: string類型的值並希望將其轉換爲String ^的函數。從std :: string轉換爲字符串^

void(String ^outValue) 
{ 
    std::string str("Hello World"); 
    outValue = str; 
} 
+2

我認爲你需要另一個標籤,因爲'字符串^'不使用C多大意義++。 – juanchopanza

+0

這是託管的C++語法。而你的功能甚至不是有效的,沒有標識符。 – Aesthete

+0

問題是這個函數是用來將一個值從C++轉換爲C#/我的意思是這個函數被C#程序調用 – Moti

回答

5

谷歌搜索顯示marshal_as(未經測試):

// marshal_as_test.cpp 
// compile with: /clr 
#include <stdlib.h> 
#include <string> 
#include <msclr\marshal_cppstd.h> 

using namespace System; 
using namespace msclr::interop; 

int main() { 
    std::string message = "Test String to Marshal"; 
    String^ result; 
    result = marshal_as<String^>(message); 
    return 0; 
} 

另見Overview of Marshaling

+0

謝謝,它的工作 – Moti

相關問題