logo资料库

编程头文件:fstream.h.doc

第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
资料共3页,全文预览结束
fstream.h __cplusplus _MSC_VER > 1000 #if #pragma once #endif #ifdef #ifndef _INC_FSTREAM #define _INC_FSTREAM #if #error ERROR: Only Mac or Win32 targets supported! #endif #ifdef // Currently, all MS C compilers for Win32 platforms default to 8 byte alignment. #pragma pack(push,8) #include !defined(_WIN32) && !defined(_MAC) _MSC_VER _DLL /* ndef _DLL */ #endif // _MSC_VER /* Define _CRTIMP */ #ifndef _CRTIMP #ifdef #define _CRTIMP __declspec(dllimport) #else #define _CRTIMP /* _DLL */ #endif #endif /* _CRTIMP */ #include #ifdef _MSC_VER // C4514: "unreferenced inline function has been removed" #pragma warning(disable:4514) // disable C4514 warning // #pragma warning(default:4514) #endif // _MSC_VER // use this to reenable, if desired typedef int filedesc; class _CRTIMP filebuf : public streambuf { public: static openprot; const int // default share/prot mode for open const int const int const int // optional share values for 3rd argument (prot) of open or constructor static static static // use (sh_read | sh_write) to allow both read and write sharing options for setmode member function static static // exclusive mode no sharing // allow read sharing // allow write sharing sh_none; sh_read; sh_write; const int const int binary; text; filebuf(); filebuf(filedesc); 1
filebuf(filedesc, char *, int); ~filebuf(); filebuf* filedesc int filebuf* filebuf* int attach(filedesc); fd() const { return (x_fd==-1) ? EOF : x_fd; } is_open() const { return (x_fd!=-1); } open(const char *, int, int = filebuf::openprot); close(); setmode(int = filebuf::text); virtual int virtual int overflow(int=EOF); underflow(); virtual streambuf* virtual streampos // virtual virtual int sync(); setbuf(char *, int); seekoff(streamoff, ios::seek_dir, int); streampos seekpos(streampos, int); private: }; filedesc int x_fd; x_fOpened; class _CRTIMP ifstream : public istream { public: ifstream(); ifstream(const char *, int =ios::in, int = filebuf::openprot); ifstream(filedesc); ifstream(filedesc, char *, int); ~ifstream(); streambuf * setbuf(char *, int); filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); } void attach(filedesc); filedesc fd() const { return rdbuf()->fd(); } int is_open() const { return rdbuf()->is_open(); } void open(const char *, int =ios::in, int = filebuf::openprot); void close(); int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); } }; class _CRTIMP ofstream : public ostream { public: ofstream(); ofstream(const char *, int =ios::out, int = filebuf::openprot); ofstream(filedesc); 2
ofstream(filedesc, char *, int); ~ofstream(); streambuf * setbuf(char *, int); filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); } void attach(filedesc); filedesc fd() const { return rdbuf()->fd(); } int is_open() const { return rdbuf()->is_open(); } void open(const char *, int =ios::out, int = filebuf::openprot); void close(); int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); } }; class _CRTIMP fstream : public iostream { public: fstream(); fstream(const char *, int, int = filebuf::openprot); fstream(filedesc); fstream(filedesc, char *, int); ~fstream(); streambuf * setbuf(char *, int); filebuf* rdbuf() const { return (filebuf*) ostream::rdbuf(); } void attach(filedesc); filedesc fd() const { return rdbuf()->fd(); } int is_open() const { return rdbuf()->is_open(); } void open(const char *, int, int = filebuf::openprot); void close(); int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); } }; // manipulators to dynamically change file access mode (filebufs only) inline ios& binary(ios& _fstrm) \ { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::binary); return _fstrm; } inline ios& text(ios& _fstrm) \ { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::text); return _fstrm; } _MSC_VER #ifdef #pragma pack(pop) #endif #endif #endif // _MSC_VER // _INC_FSTREAM /* __cplusplus */ 3
分享到:
收藏