新手在这里基本上我想将文件加载到输入流。我收到以下错误
错误C2065:'Stream':未声明的标识符。
#pragma once
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
namespace test2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
// ...
private: System::Void browse_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 )
{
//code
myStream->Close();
}
}
}
};
}
答案 0 :(得分:2)
.NET Stream
类在System.IO
命名空间中定义,因此您需要...
限定对象声明中的类型名称以及所有后续使用
IO::Stream^ myStream;
或在代码文件顶部添加using
指令
using namespace System::IO;
答案 1 :(得分:0)
您只是忘了为Stream类指定正确的命名空间:
System::IO::Stream^ myStream;