cplusplus.com
  C++ Library Reference : IOstream Library : ifstream : close
- -
º¯Êý¿â
C++º¯Êý¿â
Cº¯Êý¿â
C++º¯Êý¿â
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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
ifstream
· ifstream::ifstream
member functions:
· ifstream::close
· ifstream::is_open
· ifstream::open
· ifstream::rdbuf

-

ifstream::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 exception an exception may be thrown.

Parameters

none

Return Value

none

Example

// opening and closing a file
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  ifstream infile;

  infile.open ("test.txt");

  // >> i/o operations here <<

  infile.close();
  return 0;
}

This example simply opens and closes a file.

Basic template member declaration

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

See also

ifstream::open Open file (public member function)
filebuf::close Close file (public member function)
© Copyright © 2007-2008 ¿áÇÚÍø All Rights Reserved