【问题标题】:a value type of "void" cannot be used to initialize an entity type of "System::string^"“void”的值类型不能用于初始化“System::string^”的实体类型
【发布时间】:2016-05-17 11:49:06
【问题描述】:

我正在关注 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();
        }
    }
}

【问题讨论】:

    标签: string winforms c++-cli void


    【解决方案1】:

    错别字:

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

    【讨论】:

    • 这是我熬夜超过 24 小时后得到的结果,除此之外,“嘿,我将在我的期中考试中做最后的润色”,这也是我第二次使用 = 而不是 +
    • @liftedplane 它发生了,但这就是为什么睡得好如此重要)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多