1

这里的新手基本上我想将文件加载到输入流。我收到以下错误

错误 C2065:“流”:未声明的标识符。

#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();
            }
        }
    }

  };
} 
4

2 回答 2

2

.NETStream类是在System.IO命名空间中定义的,因此您要么需要……

  • 在对象声明和所有后续使用中限定类型的名称

    IO::Stream^ myStream;
    
  • using在代码文件的顶部添加指令

    using namespace System::IO;
    
于 2013-07-07T10:25:56.017 回答
0

您只是忘记为 Stream 类指定正确的命名空间:

System::IO::Stream^ myStream;
于 2013-07-07T10:26:12.027 回答