basic_ofstream::is_open

指出檔案是否為開啟狀態。

bool is_open( ) const;

傳回值

true ,如果檔案是開啟的,則為 false 。

備註

成員函式傳回 rdbuf -> is_open

範例

// basic_ofstream_is_open.cpp
// compile with: /EHsc
#include <fstream>
#include <iostream>

int main( ) 
{
   using namespace std;
   ifstream file;
   // Open and close with a basic_filebuf
   file.rdbuf( )->open( "basic_ofstream_is_open.txt", ios::in );
   file.close( );
   if (file.is_open())
      cout << "it's open" << endl;
   else
      cout << "it's closed" << endl;
}

Output

it's closed

需求

標題: <fstream>

命名空間: std

請參閱

參考

basic_ofstream Class

iostream 程式設計

iostreams 慣例