🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #839

Help getFileHandle()

#839
From: Maya
Date: Tue, 26 Nov 2002 22:48
74 lines
3831 bytes
Opening and closing files is such a routine that I want to write a class
that will handle the opening and closing of files, and I have already done
most of the work. My problems is when I want to get the file handle, I
don't know how to do this, exactly. Below is the part of the class that is
causing the problem

   class FileIO
   {
      public:
         // file modes
         ios::openmode RW_OPEN_BIN;
      private:
         std::fstream f;
         std::string file_name;
         ios::openmode mode;
         fileprot permission;
       
      public:
         FileIO();
         ~FileIO();

         //Setters
         bool setFileName( const std::string&); bool
         setMode(ios::openmode);
         bool setPermission(const fileprot);

         //Getters
         const char*    getFileName()   const {return file_name.c_str();}
         ios::openmode  getMode()       const {return mode;             }
         const fileprot getPermission() const {return permission;       }
         const std::fstream&  getFileHandle() { return f;               }


         bool Create()throw(FileIOEx);
        
   }; //File


FileIO::FileIO(){
   //Open an existing binary file for reading and writing RW_OPEN_BIN =
   std::ios::in | std::ios::out | std::ios::binary; mode = this->RW_OPEN;
}
FileIO::~FileIO(){
   if(f.is_open()){f.close();}
}
//Setters
bool FileIO::setFileName(const std::string& str){
   file_name = str;
   return false;
}
bool FileIO::setMode(ios::openmode m){
   mode = m;
   return false;
}
bool FileIO::setPermission(const fileprot per){
   permission = per;
   return false;
}
bool  FileIO::Create() throw(FileIOEx){
   f.open(this->getFileName(), this->getMode() ) return false;
}

int main(){
   FileIO fio;
   fio.setFileName("File");
   fio.setMode(RW_OPEN_BIN);
   fio.Create();
   std::fstream& f = fio.getFileHandle(); 
   f << "Need Help!" << std::endl; // Here is the problem!!!!!
   return 0;
}
Doe anyone know how to go about getting the file handle in this way?

Thanks in advance
Technical Details
Message-ID: <pan.2002.11.26.22.48.05.391738@canada.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!news.compaq.com!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!nntp2.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!nntp.vif.com!news.vif.com.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,cc989fe1e1d8a53f,start
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,cc989fe1e1d8a53f,start
X-Google-Attributes: gid114592,public
X-Google-Thread: 10ba33,cc989fe1e1d8a53f,start
X-Google-Attributes: gid10ba33,public
X-Google-ArrivalTime: 2002-11-26 21:34:04 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!news.compaq.com!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!nntp2.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!nntp.vif.com!news.vif.com.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 26 Nov 2002 23:33:53 -0600
From: "Maya" <escalante@canada.com>
Organization: E-Comm
Subject: Help getFileHandle()
Date: Wed, 27 Nov 2002 00:48:14 +0200
User-Agent: Pan/0.13.1 (It's always funny until somebody immanentizes the eschaton (Debian GNU/Linux))
Message-ID: <pan.2002.11.26.22.48.05.391738@canada.com>
Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,gnu.g++.help
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Cache-Post-Path: www.vif.com!unknown@ip216-239-79-118.vif.net
X-Cache: nntpcache 2.4.0b4 (see http://www.nntpcache.org/)
Lines: 74
NNTP-Posting-Host: 216.239.64.141
X-Trace: sv3-sKhK41LU+T0/xvUjANP/9LgaPO6EOp8GDC8Sovkq9aszMuwELjZLqRP2EtDZbz6ctNhZhhySX6WiAk6!5Sky08EaeOu1CxjR7vdtqLILKhpsv8zDfsfGOYibvcZ7iPz8p10q2vfw+LUQFuu07rOwVAXWNZor!41sf
X-Complaints-To: abuse@vif.com
X-DMCA-Complaints-To: abuse@vif.com
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.1