"void" 的值类型不能用于初始化 "System::string^" 的实体类型
a value type of "void" cannot be used to initialize an entity type of "System::string^"
我正在关注 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^ strCharName = openCharDialog1->InitialDirectory + openCharDialog1->FileName;
^
我正在关注 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^ strCharName = openCharDialog1->InitialDirectory + openCharDialog1->FileName;
^