⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fstream

📁 realview22.rar
💻
📖 第 1 页 / 共 2 页
字号:


template<class _CharT, class _Traits>
class basic_ifstream: public basic_istream<_CharT, _Traits>
{
public:

    typedef _CharT                          char_type;
    typedef _Traits                         traits_type;
    typedef _TYPENAME traits_type::int_type int_type;
    typedef _TYPENAME traits_type::pos_type pos_type;
    typedef _TYPENAME traits_type::off_type off_type;

    // NOTE: the ctors below pass the address of an unitialized
    //       member variable, _C_filebuf, to a base class ctor
    // the variable will be initialized only *after* the base
    // class ctor returns

    basic_ifstream ()
        : basic_istream<char_type, traits_type> (rdbuf ()) { }

    _EXPLICIT basic_ifstream (const char        *__name,
                              ios_base::openmode __mode = ios_base::in,
                              long               __prot = 0666)
        : basic_istream<char_type, traits_type> (rdbuf ()) {
        open (__name, __mode, __prot);
    }

#ifndef  _RWSTD_NO_EXT_FILEBUF

    // extensions - associate this with an open file and set buffer
    basic_ifstream (int __fd, char_type *__buf = 0,
                    streamsize __n = _RWSTD_DEFAULT_BUFSIZE)
        : basic_istream<char_type, traits_type> (rdbuf ()) {
        open (__fd, __buf, __n);
    }

    basic_ifstream (FILE *__fptr, char_type *__buf = 0,
                    streamsize __n = _RWSTD_DEFAULT_BUFSIZE)
        : basic_istream<char_type, traits_type> (rdbuf ()) {
        open (__fptr, __buf, __n);
    }

#endif  //_RWSTD_NO_EXT_FILEBUF
    
    // NOTE: the pointer returned from rdbuf() may be different from
    //       the one passed to basic_ios<>::rdbuf (basic_filebuf<>*)

    basic_filebuf<char_type, traits_type>* rdbuf() const {
        // necessary to help SunPro 5.0/T9
        typedef basic_ifstream <char_type, traits_type> __self_type;
        return &_RWSTD_CONST_CAST (__self_type*, this)->_C_filebuf;
    }

    bool is_open () const {
        return rdbuf ()->is_open ();
    }

    void open (const char         *__name,
               ios_base::openmode  __mode = ios_base::in,
               long                __prot = 0666) {
        this->clear (rdbuf ()->open (__name, __mode |= ios_base::in, __prot)
                     ? ios_base::goodbit : ios_base::failbit);
    }

#ifndef  _RWSTD_NO_EXT_FILEBUF

    // extensions - associate this with an open file and set buffer
    void open (int __fd, char_type *__buf=0,
               streamsize __n=_RWSTD_DEFAULT_BUFSIZE) {
        this->clear (rdbuf ()->open (__fd, __buf, __n) ?
                     ios_base::goodbit : ios_base::failbit);
    }

    void open (FILE *__fptr, char_type *__buf=0,
               streamsize __n= _RWSTD_DEFAULT_BUFSIZE) {
        this->clear (rdbuf ()->open (__fptr, __buf, __n) ?
                     ios_base::goodbit : ios_base::failbit);
    }

#endif  //_RWSTD_NO_EXT_FILEBUF

    void close () {
        if (!rdbuf ()->close ())
            this->setstate (ios_base::failbit);
    }

private:
    basic_filebuf<char_type, traits_type> _C_filebuf;
};


template<class _CharT, class _Traits>
class basic_ofstream: public basic_ostream<_CharT, _Traits>
{
public:

    typedef _CharT                          char_type;
    typedef _Traits                         traits_type;
    typedef _TYPENAME traits_type::int_type int_type;
    typedef _TYPENAME traits_type::pos_type pos_type;
    typedef _TYPENAME traits_type::off_type off_type;

    // NOTE: the ctors below pass the address of an unitialized
    //       member variable, _C_filebuf, to a base class ctor
    // the variable will be initialized only *after* the base
    // class ctor returns

    basic_ofstream ()
        : basic_ostream<char_type, traits_type> (rdbuf ()) { }

    _EXPLICIT basic_ofstream (const char         *__name,
                              ios_base::openmode  __mode = ios_base::out,
                              long                __prot = 0666)
        : basic_ostream<char_type, traits_type> (rdbuf ()) {
        open (__name, __mode, __prot);
    }

#ifndef _RWSTD_NO_EXT_FILEBUF

    // extensions - associate this with an open file and set buffer
    basic_ofstream (int __fd, char_type *__buf=0,
                    streamsize __n= _RWSTD_DEFAULT_BUFSIZE)
        : basic_ostream<char_type, traits_type> (rdbuf ()) {
        open (__fd, __buf, __n);
    }
    
    basic_ofstream (FILE *__fptr, char_type *__buf=0,
                    streamsize __n= _RWSTD_DEFAULT_BUFSIZE)
        : basic_ostream<char_type, traits_type> (rdbuf ()) {
        open (__fptr, __buf, __n);
    }

#endif  //_RWSTD_NO_EXT_FILEBUF
    
    // NOTE: the pointer returned from rdbuf() may be different from
    //       the one passed to basic_ios<>::rdbuf (basic_filebuf<>*)

    basic_filebuf<char_type, traits_type>* rdbuf () const {
        // necessary to help SunPro 5.0/T9
        typedef basic_ofstream <char_type, traits_type> _SelfT;
        return &_RWSTD_CONST_CAST (_SelfT*, this)->_C_filebuf;
    }

    bool is_open () const {
        return rdbuf ()->is_open ();
    }
     
    void open (const char         *__name,
               ios_base::openmode  __mode = ios_base::out,
               long                __prot = 0666) {
        this->clear (rdbuf ()->open (__name, __mode |= ios_base::out, __prot)
                     ? ios_base::goodbit : ios_base::failbit);
    }

#ifndef _RWSTD_NO_EXT_FILEBUF

    // extensions - associate this with an open file and set buffer
    void open (int  __fd, char_type *__buf=0,
               streamsize __n=_RWSTD_DEFAULT_BUFSIZE) {
        this->clear (rdbuf ()->open (__fd, __buf, __n) ?
                     ios_base::goodbit : ios_base::failbit);
    }

    void open (FILE *__fp, char_type *__buf=0,
               streamsize __n= _RWSTD_DEFAULT_BUFSIZE) {
        this->clear (rdbuf ()->open (__fp, __buf, __n) ?
                     ios_base::goodbit : ios_base::failbit);
    }

#endif //_RWSTD_NO_EXT_FILEBUF
    
    void close() {
        if (!rdbuf ()->close ())
            this->setstate (ios_base::failbit);
    }

private:
    basic_filebuf<char_type, traits_type> _C_filebuf;
};


template<class _CharT, class _Traits>
class basic_fstream: public basic_iostream<_CharT, _Traits>
{
public:

    typedef _CharT                          char_type;
    typedef _Traits                         traits_type;
    typedef _TYPENAME traits_type::int_type int_type;
    typedef _TYPENAME traits_type::pos_type pos_type;
    typedef _TYPENAME traits_type::off_type off_type;

    // NOTE: the ctors below pass the address of an unitialized
    //       member variable, _C_filebuf, to a base class ctor
    // the variable will be initialized only *after* the base
    // class ctor returns

    basic_fstream ()
        : basic_iostream<char_type, traits_type>(rdbuf ()) { }

    _EXPLICIT
    basic_fstream (const char         *__name,
                   ios_base::openmode  __mode = ios_base::in | ios_base::out,
                   long                __prot = 0666)
        : basic_iostream<char_type, traits_type>(rdbuf ()) {
        open (__name, __mode, __prot);
    }

#ifndef _RWSTD_NO_EXT_FILEBUF

    // extensions - associate this with an open file and set buffer
    basic_fstream (int __fd, char_type *__buf=0,
                   streamsize __n = _RWSTD_DEFAULT_BUFSIZE)
        : basic_iostream<char_type, traits_type>(rdbuf ()) {
        open (__fd, __buf, __n);
    }

    basic_fstream (FILE *__fptr, char_type *__buf=0,
                   streamsize __n = _RWSTD_DEFAULT_BUFSIZE)
        : basic_iostream<char_type, traits_type>(rdbuf ()) {
        open (__fptr, __buf, __n);
    }

#endif //_RWSTD_NO_EXT_FILEBUF

    // NOTE: the pointer returned from rdbuf() may be different from
    //       the one passed to basic_ios<>::rdbuf (basic_filebuf<>*)

    basic_filebuf<char_type, traits_type>* rdbuf() const {
        // necessary to help SunPro 5.0/T9
        typedef basic_fstream <char_type, traits_type> _SelfT;
        return &_RWSTD_CONST_CAST (_SelfT*, this)->_C_filebuf;
    }

    bool is_open () const {
        return rdbuf ()->is_open ();
    }

    void open (const char         *__name,
               ios_base::openmode  __mode = ios_base::in | ios_base::out,
               long                __prot = 0666) {
        this->clear (rdbuf ()->open (__name, __mode, __prot)
                     ? ios_base::goodbit : ios_base::failbit);
    }

#ifndef _RWSTD_NO_EXT_FILEBUF

    // extensions - associate this with an open file and set buffer"
    void open (int __fd, char_type *__buf=0,
               streamsize __n= _RWSTD_DEFAULT_BUFSIZE) {
        this->clear (rdbuf ()->open (__fd, __buf, __n) ?
                     ios_base::goodbit : ios_base::failbit);
    }
    
    void open (FILE *__fptr, char_type *__buf=0,
               streamsize __n= _RWSTD_DEFAULT_BUFSIZE) {
        this->clear (rdbuf ()->open (__fptr, __buf, __n) ?
                     ios_base::goodbit : ios_base::failbit);
    }

#endif //_RWSTD_NO_EXT_FILEBUF

    void close () {
        if (!rdbuf ()->close ())
            this->setstate (ios_base::failbit);
    }

private:
    basic_filebuf<char_type, traits_type> _C_filebuf;
};


_RWSTD_INSTANTIATE_2 (class _RWSTD_EXPORT
                      basic_filebuf<char, char_traits<char> >);

#ifndef _RWSTD_NO_WCHAR_T
_RWSTD_INSTANTIATE_2 (class _RWSTD_EXPORT
                      basic_filebuf<wchar_t, char_traits<wchar_t> >);
#endif   // _RWSTD_NO_WCHAR_T


_RWSTD_NAMESPACE_END   // std


#if _RWSTD_DEFINE_TEMPLATE (BASIC_FILEBUF)
#  include <fstream.cc>
#endif


#endif   // _RWSTD_FSTREAM_INCLUDED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -