值类型" void"不能用于初始化实体类型" System :: string ^"

时间:2016-02-07 21:04:08

标签: string winforms c++-cli void

我正在关注youtube上有关创建表单的教程,并且在完成他正在做的事情时我得到了这个错误。我一直在搜索,我无法弄明白。

这是视频https://www.youtube.com/watch?v=lkhGpWUclc8&list=PLS1QulWo1RIZz6uDid--I09EOImRmPHS0&index=22

下面是代码

以粗体显示的部分是抛出错误的唯一部分

String ^ strCharName = openCharDialog1 - > InitialDirectory = openCharDialog1-> FileName;

private: System::Void openButton_Click(System::Object^  sender, System::EventArgs^  e) {

    Stream^ openCharacter;
    OpenFileDialog^ openCharDialog1 = gcnew OpenFileDialog;

    if (openCharDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
    {
        if ((openCharacter = openCharDialog1->OpenFile()) != nullptr )
        {

            String^ strCharName = openCharDialog1->InitialDirectory = openCharDialog1->FileName;

            MessageBox::Show(strCharName);

            openCharacter->Close();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

错字:

String^ strCharName = openCharDialog1->InitialDirectory + openCharDialog1->FileName;
                                                        ^