如何在C++/CLI中定义字符串数组?

Gho*_*ost 3 c++-cli visual-studio-2010

这有什么不对:

我收到所有5个定义的错误:

 error C3698: 'System::String ^' : cannot use this type as argument of 'gcnew'
 error C2512: 'System::String::String' : no appropriate default constructor available    



array<String^>^ arr = gcnew array<String^>
{
    gcnew String^ "Madam I'm Adam.",    
    gcnew String^ "Don't cry for me,Marge and Tina.",   //error C2143: syntax error : missing '}' before 'string'   AND error C2143: syntax error : missing ';' before 'string'
    gcnew String^ "Lid off a daffodil.",
    gcnew String^ "Red lost Soldier.",
    gcnew String^ "Cigar? Toss it in a can. It is so tragic."
}
Run Code Online (Sandbox Code Playgroud)

Fré*_*idi 5

你不应该gcnew在数组初始化器内部使用:

array<String^>^ arr = gcnew array<String^> {
    "Madam I'm Adam.",    
    "Don't cry for me,Marge and Tina.",
    "Lid off a daffodil.",
    "Red lost Soldier.",
    "Cigar? Toss it in a can. It is so tragic."
};
Run Code Online (Sandbox Code Playgroud)