2011-03-01 41 views
1

我如何關閉C++中的IStream?如何關閉IStream?

+0

調用其Release()方法。 – 2011-03-01 19:12:05

+4

你是指'std :: istream'還是COM'IStream'?你是怎麼打開它的?這可能會確定關閉它的正確方法。 – 2011-03-01 19:15:46

回答

1

檢查這個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; 
} 
0

你可以用ifstream :: close關閉文件iostreams。關閉一個istream並沒有什麼意義 - 它應該關閉shell才能啓動程序嗎?

您可以刷新一個的iostream,以確保輸出寫入

3

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