如何在c++中关闭IStream?
发布于 2011-03-02 02:31:15
检查此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;
}发布于 2011-03-02 04:23:59
如果您指的是COM IStream,只需调用IUnknown::Release()即可。
发布于 2011-03-02 02:29:26
您可以使用ifstream::close关闭文件ifstream。关闭一个istream并没有什么实际意义--它应该关闭启动程序的shell吗?
您可以刷新iostream以确保写入输出
https://stackoverflow.com/questions/5158697
复制相似问题