我正在尝试使用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:'Stream':未声明的标识符c:\ users \
错误2错误C2065:'myStream':未声明的标识符
错误3错误C2065:'myStream':未声明的标识符
错误4错误C2065:'myStream':未声明的标识符
错误5错误C2227:' - >关闭'的左侧必须指向
答案 0 :(得分:0)
将此添加到代码文件的顶部,这已删除了我的错误。
使用命名空间系统:: IO