Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
filebuf
fstream
ifstream
ios
iostream
ios_base
istream
istringstream
ofstream
ostream
ostringstream
streambuf
stringbuf
stringstream
objects:
cerr
cin
clog
cout
types:
fpos
streamoff
streampos
streamsize
fstream
fstream::fstream
member functions:
fstream::close
fstream::is_open
fstream::open
fstream::rdbuf


fstream::close

public member function
void close ( );

Close file

Closes the file currently associated with the object, disassociating it from the stream. Any pending output sequence is written to the physical file.

The function effectively calls rdbuf()->close().

The function fails if no file is currently open (associated) with this object.

On failure, the failbit internal state flag is set (which can be checked with member fail), and depending on the value set with exceptions an exception may be thrown.

Parameters

none

Return Value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// opening and closing a file
#include <iostream>
#include <fstream>
using namespace std;
int main () {
  fstream filestr;
  filestr.open ("test.txt");
  // >> i/o operations here <<
  filestr.close();
  return 0;
}


Basic template member declaration

( basic_fstream<charT,traits> )
 
void close ( );


See also