   problem with file i/o
  I am just learning about file I/O.  I typed in this in my compiler:#include <fstream.h>#include <iostream>using namespace std;int main()//returns 1 on error{    char fileName[80];    char buffer[255];    cout << "Please re-enter the file name: ";    cin >> fileName;   ifstream fin(fileName);    if(fin) //already exists?    {  cout << "Current file contents:\n";  char ch;  while(fin.get(ch))cout << ch;  cout << "\n***End of file contents.***\n";    }    fin.close();   cout << "\nOpening " << fileName << " in append mode...\n";   ofstream fout(fileName, ios::app);    if(!fout)    {   cout << "Unable to open " << fileName << " for appending.\n";   return(1);    }   cout << "\nEnter text for the file: ";    cin.ignore(1, '\n');    cin.getline(buffer, 255);    fout << buffer << "\n";    fout.close();   fin.open(fileName);    //reassign fin object!    if(!fin)    {  cout << "Unable to open " << fileName << " for reading.\n";  return(1);    }    cout << "\nHere's the contents of the file:\n";    char ch;    while(fin.get(ch))  cout << ch;    cout << "\n***End of the file contents.***\n";    fin.close();    return 0;}and its all fine until it is trying to reopen the file after writing to it in append mode, it just fails to open it.  I was hoping someone here could tell me why.  Thank you for the help.   
  Known defect in the library specification: stream flags are not cleared when a stream is reopened. Add a fin.clear() prior to re-opening it.   ;  Wewt it worked, thank you very much for the help!   ;  I always wondered about that.   ;  As a note Dark, include your source-code inside of [ source] and [ /source] tags (without the spaces).   ;Quote:Original post by DarkSuicide#include <fstream.h>That should be #include <fstream>.  No .h on C++ standard library headers.Quote: char fileName[80];char buffer[255];cout << "Please re-enter the file name: ";cin >> fileName;You don't want an array of characters.  You want a string.  So use a string.  As it stands you have a buffer overflow error just waiting to happen.  You know, the kind of things that virus writers love to take advantage of.  Don't wait, get out of the habit of writing them now.Enigma   