fstream 这个header用在于使用input、output data\ file string
Just as an added note, there are still situations where it is necessary to explicitly close a file. Say you have a vector fileNames of files you need to process
std::ifstream
inFile;
for( std::vector< std::string >::size_type i = 0; i < fileNames.size(); ++i )
{
inFile.clear(); i
nFile.open( fileNames[ i ] );// code to process the fileinFile.close();}
The reason you need to call close() at the end of the loop is that trying to open a new file without closing the first file will fail. The call to clear() at the beginning of the loop is necessary because closing a file and then opening another file does not clear the stream.