.


:




:

































 

 

 

 





 

, , :

1. (my_manip) : ,

ostream& (*f)(ostream&,< >);

2. (my_manip) .

3. , operator<<. my_manip, () ostream ostream *f. ,

typedef far ostream&(far *PTF)(ostream&,int,int,char);

class my_man{

int w;int n;char fill;

PTF f;

public:

//

my_man(PTF F,int W,int N,char FILL):f(F),w(W),n(N),fill(FILL){}

friend ostream& operator<<(ostream&,my_man);

};

ostream& operator<<(ostream& out,my_man my)

{return my.f(out,my.w,my.n,my.fill);}

 

4. *f (fmanip), . . ,

ostream& fmanip(ostream& s,int w,int n,char fill)

{s.width(w);

s.flags(ios::fixed);

s.precision(n);

s.fill(fill);

return s;}

5. (wp) , my_manip, f fmanip. ,

my_man wp(int w,int n,char fill)

{return my_man(fmanip,w,n,fill);}

, <iomanip.h>:

OMANIP(int)

IMANIP(int)

IOMANIP(int)

 

.

. ios enum.

public:

enum io_state{

goodbit, // 000

eofbit, // 001

failbit, // 002

badbit, // 004

hardfail // 008

};

, ios, state. int rdstate().

, :

int bad(); 1, badbit hardfail

int eof(); 1, eofbit

int fail(); 1, failbit, badbit hardfail

int good(); 1, goodbit

 

 

>> , .

-

 

:

ofstream ;

ifstream ;

fstream /.

:

fstream();

, .

fstream(const char* name,int mode,int p=filebuf::openprot);

, name, , mode p. , . mode=ios::out, , .

ios :

in -

out -

ate - . , ;

app - . seekp() ;

trunc - ;

nocreate - , ;

noreplace - , ;

binary- .

,

void open(const char* name,int mode,int p=filebuf::openprot);

void fstreambase::close();

, . . .

 

, :

1. filebuf

filebuf fbuf;

filebuf ()

fbuf.open(,ios::in);

filebuf

istream stream(&fbuf);

2. fstream (ifstream, ofstream)

fstream stream;

, filebuf

stream.open(,ios::in);

3. fstream, ,

fstream stream(,ios::in);





:


: 2016-11-02; !; : 441 |


:

:

, .
==> ...

1271 - | 1235 -


© 2015-2024 lektsii.org - -

: 0.011 .