C++ Problem

Guo Yang gyang at njit.edu
Thu Jul 15 16:16:00 UTC 2004


Hello,

I am learning C++ right now. I got a strange problem about fstream
class. The program below I tried on a Fedora Core 3 test 1 platform
always fails to open the 'test.cpp' file (which is the program file
itself). But the same program works on Windows without any problem. So
did I do something wrong or the implementation of the c++ library
doesn't work? 

Thank you very much for help. 

#include <iostream>
#include <fstream>

using namespace std;

int main () {

  fstream filestr("test.cpp", ios::in|ios::out|ios::app);

  if (filestr.is_open())
  {
    cout << "File successfully open" << endl;
    filestr << "Help wanted!" << endl;
    filestr.close();
  }
  else
  {
    cerr << "Error opening file" << endl;
  }

  return 0;
}


Guo





More information about the test mailing list