boost/filesystem/fstream.hpp

Introduction

The C++ Standard Library's <fstream> header uses const char* to pass arguments representing file names, with that usage occurring seven times.

The Filesystem Library's fstream.hpp header provides equivalent components, in namespace boost::filesystem, except that the seven  const char* arguments have been replaced by const path& arguments.

The Filesystem Library's fstream.hpp header simply uses the <fstream> standard library components as base classes, and then redeclares constructors and open functions to take arguments of type const path& instead of const char*.

For documentation beyond the synopsis, see the tutorial and examples.

Synopsis

namespace boost
{
  namespace filesystem
  {
    template < class charT, class traits = std::char_traits<charT> >
    class basic_filebuf : public std::basic_filebuf<charT,traits>
    {
    public:
      virtual ~basic_filebuf() {}

      std::basic_filebuf<charT,traits> * open( const path & file_ph,
        std::ios_base::openmode mode );
    };

    typedef basic_filebuf<char> filebuf;
    typedef basic_filebuf<wchar_t> wfilebuf;

    template < class charT, class traits = std::char_traits<charT> >
    class basic_ifstream : public std::basic_ifstream<charT,traits>
    {
    public:
      basic_ifstream() {}
      explicit basic_ifstream( const path & file_ph,
        std::ios_base::openmode mode = std::ios_base::in );
      virtual ~basic_ifstream() {}
      void open( const path & file_ph,
        std::ios_base::openmode mode = std::ios_base::in );
    };

    typedef basic_ifstream<char> ifstream;
    typedef basic_ifstream<wchar_t> wifstream;

    template < class charT, class traits = std::char_traits<charT> >
    class basic_ofstream : public std::basic_ofstream<charT,traits>
    {
    public:
      basic_ofstream() {}
      explicit basic_ofstream( const path & file_ph,
        std::ios_base::openmode mode = std::ios_base::out );
      virtual ~basic_ofstream() {}
      void open( const path & file_ph,
        std::ios_base::openmode mode = std::ios_base::out );
    };

    typedef basic_ofstream<char> ofstream;
    typedef basic_ofstream<wchar_t> wofstream;

    template < class charT, class traits = std::char_traits<charT> >
    class basic_fstream : public std::basic_fstream<charT,traits>
    {
    public:
      basic_fstream() {}
      explicit basic_fstream( const path & file_ph,
        std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out );
      virtual ~basic_fstream() {}
      void open( const path & file_ph,
        std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out );
    };
 
    typedef basic_fstream<char> fstream;
    typedef basic_fstream<wchar_t> wfstream;
  } // namespace filesystem
} // namespace boost

Revised 12 March, 2004

© Copyright Beman Dawes, 2002

Use, modification, and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt)