如何关闭IStream?

时间:2011-03-01 18:26:28

标签: c++ stream

如何在c ++中关闭IStream?

3 个答案:

答案 0 :(得分:5)

如果您的意思是COM IStream,只需调用IUnknown :: Release()。

答案 1 :(得分:2)

选中reference

// read a file into memory
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  int length;
  char * buffer;

  ifstream is;
  is.open ("test.txt", ios::binary );

  // get length of file:
  is.seekg (0, ios::end);
  length = is.tellg();
  is.seekg (0, ios::beg);

  // allocate memory:
  buffer = new char [length];

  // read data as a block:
  is.read (buffer,length);
  is.close();

  cout.write (buffer,length);

  delete[] buffer;
  return 0;
}

答案 2 :(得分:0)

您可以使用ifstream :: close关闭文件iostream。关闭一个istream并没有多大意义 - 如果它关闭shell,程序是从哪个开始的?

您可以刷新iostream以确保输出