gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:55:43 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com