windows - C++ -'Stream' 未声明的标识符

标签 windows visual-studio c++-cli

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

error C2065: 'Stream' : undeclared identifier.

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

  };
} 

最佳答案

.NET Stream类在 System.IO 命名空间中定义,因此您需要……

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

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

    using namespace System::IO;
    

关于windows - C++ -'Stream' 未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17511165/

相关文章:

javascript - Windows 应用程序开发 - ListView 检索数据

windows - 为什么我会收到足迹 FPMCP 服务器错误

windows - 从外部应用程序获取正在运行的bat文件的名称

vb.net - 创建一个 "clone"的这个对象,不是指向它

c++-cli - C++/CLI中的跟踪引用

enums - C++/CLI : Casting from unmanaged enum to managed enum

windows - 将 Git 分支添加到命令提示符

c - 如果必须终止控制台,如何查看 Visual Studio 的输出?

c# - 如何将 C++ 代码包装到具有大量 float*(代表点)的 CLI 中?

c# - "ConvertPdbToMdb"任务意外失败