-1

我正在尝试使用 c++ Visual Studio 2010 中的 Windows 应用程序表单浏览文件。此代码给出以下错误。任何人都可以帮助解决问题

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

      Stream^ myStream;
      OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

      openFileDialog1->InitialDirectory = "c:\\";
      openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
      openFileDialog1->FilterIndex = 2;
      openFileDialog1->RestoreDirectory = true;

      if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
      {
            if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
            {
                // Insert code to read the stream here.
                myStream->Close();
            }
      }

}

错误 1 ​​错误 C2065:“流”:未声明的标识符 c:\users\

错误 2 错误 C2065:“myStream”:未声明的标识符

错误 3 错误 C2065:“myStream”:未声明的标识符

错误 4 错误 C2065:“myStream”:未声明的标识符

错误 5 错误 C2227: '->Close' 的左侧必须指向

4

1 回答 1

0

将此添加到代码文件的顶部,这已消除了我的错误。

使用命名空间系统::IO

于 2013-10-16T06:18:28.043 回答