basic_ofstream::is_open

指示文件是否处于打开状态。

bool is_open( ) const;

返回值

true,如果打开文件,则为 false。

备注

成员函数返回 ->is_openrdbuf

示例

// 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 类

iostream 编程

iostreams 约定