/

  1. N- .
  2. /
  3. , n- .

/ get () put (). - put (), ; , - get (). get () . get () put ():

istream & get (char & ch);

ostream & put (char ch);

get () ch. , , EOF. put () ch .

C ++ read () write (). :

istream & read (unsigned char * buf, int num);

ostream & write (const unsigned char * buf, int num);

read () num , buf. write () num , buf.

, num, read () , , . ij, , -, gcount (), : int gcount ();

, .

:

1. - , get ().

#indude

#include

main ()

{Char ch;

ifstream in ( "test");

if (! in)

{Cout << " | n";

return 1;

}

while (! in.eof ())

{In.get (ch);

out << ch;

}

return 0;

}

2. put () , . ($).

#include

#include

main ()

{Char ch;

ofstream out ( "test");

if (! out)

{Cout << " | n";

return 1;

}

cout << " $ \ n";

do

{Cout << ":";

cin.get (ch);

out.put (ch);

} While (ch! = '$');

cut. close () :,

}

, cin get (). , >> . get () .

3. write () double ' test read () :

#include

#include

#include

main ()

{Ofstream fout ( "test"); //

if (! fout)

{Cout << " \ n";

return 1;

}

double num = 100.45;

char str [] = " ";

out .write ((char *) & num, sizeof (double));

out.write (str, strlen (str));

out.close ();

ifstream in ( "test"); //

if (! in)

{Cout << " \ n";

return 1;

}

double num;

char str [80];

in. read ((char *) & num, sizeof (double));

in. read (str, 15);

cout << num << '' << str;

in.close ();

return 0;

}

(char *) write () read () , . C ++ , .

4. double , . , .

// gcount ()

#include

#include

main ()

{Ofstream out ( "test");

if (! out]

{Cout << " \ n";

return 1;

}

double nums [4] = {1.l, 2.2, 3.3, 4.4};

out. write ((char *) & nums, sizeof (nums));

out.close ();

ifstream in ( "test");

if (! in)

{Cout << " \ n";

return 1;

}

in.read ((char *) & nums, sizeof (nums));

for (i = 0; i <4; i ++)

cout << nums [i];

cout << "\ n";

cout << in.gcount () << " \ n";

return 0;

}



- | /

| _. _ | | | ' | Int fseek (FILE * stream, long offset, int origin). | | | Ͳ - | ֲ |

© um.co.ua -