.


:




:

































 

 

 

 


-




- - >> <<. :

#include <fstream.h>// 61

int main(){

ofstream fout("test"); /* c */

if(!fout) { cout << " \n";

return 1; }

fout << "!\n";

fout << 100 << ' ' << hex << 100 << endl;

fout.close();

ifstream fin("test"); //

if(!fin) {cout << " \n";return 1;}

char str[80];

int i;

fin >> str >> i;

cout << str << ' ' << i << endl;

fin.close();

return 0; }

<< , :

/* - Coord */

#include <iostream.h>// 62

class Coord {

public:

int x,y;//

Coord() {x=0;y=0;}

Coord(int i,int j) {x=i;y=j;}

};

// coord

ostream &operator<<(ostream &stream, Coord ob){

stream <<ob.x<<,<<ob.y<<\n;

return stream;

}

int main(){

Coord a(1,1), b(10,23);

cout <<a<<b;

return 0; }

() :

istream &operator>>(istream &stream, _ ob){

//

return stream;

}

- : istream &get(char &ch); ostream &put(char ch);

:

#include <iostream.h>// 63

#include <fstream.h>

int main(int argc, char *argv[ ]) {

char ch;

if(argc!=2) {

cout << ":WRITE<_>\n";

return 1;}

ofstream out(argv[1]);

if(!out) {cout << " \n";return 1; }

cout << " $\n";

do {

cout << ": ";

cin.get(ch);

out.put(ch);

} while (ch!='$');

out.close();

return 0; }

- , - n :

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

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

#include <iostream.h>// 64

#include <fstream.h>

#include <string.h>

int main() {

ofstream out("test", ios::binary);/* */

if(!out) {cout << " \n";return 1;}

double num = 100.45;

char str[ ] = " ";

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

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

out.close();

return 0; }

seekg(), seekp(), tellp(). seekg() , seekp() . . , (ios::beg) (ios::cur) (ios::end). tellp().

, :

bad() , ;

clear() ;

eof() , ;

fail() , ;

good() , ;

rdstate() .

, .





:


: 2015-10-01; !; : 425 |


:

:

, .
==> ...

2014 - | 1815 -


© 2015-2024 lektsii.org - -

: 0.009 .