.


:




:

































 

 

 

 


-




. . .

-. - , . -:

-;

- ;

- ( ).

, .

, , .

, ( , , ). , , . , . , .

:

( );

, , , ;

- ;

;

.

- <stdio.h>.

, , . . . FILE, <stdio.h>. , . . , , . . FILE.

#include <stdio.h>;

........

FILE *fp;

............

fp= fopen(t.txt, r);

fopen(<_>,<_>) - .

:

r , , .
w , , , , .
a , , , , ,
r+ , , , .
w+ , , , , .
a+ , , , , ,

(t) (b) . . :

r+b rb - () ;

r+t rt .

stdio.h EOF, ( ).

:

, ( );

( );

( ) . .

NULL (0). , 0.

<stdio.h>

void perror (const char*s);

 

if ((fp=fopen(t.txt, w)==NULL)

{

//

perror(\n );

exit(0);

}

,

fclose(<__>);

, , :

(stdin);

(stdout);

(stderr).

stdin , stdout stderr - . - :

getchar()/putchar() - ;

gets()/puts() - ;

scanf()/printf() /.

- , .

- :

int fgetc(FILE*fp), fp , . int fp. , EOF.

int fputc(int c, FILE*fp), fp , , c int, . fp int. , EOF.

- :

char* fgets(char* s,int n,FILE* f), char*s , , int n , FILE* f , .

n-1 \n. . \0. , 0.

int puts(char* s, FILE* f), char*s , , FILE* f , .

(\0) . EOF, , .

- :

int fread(void*ptr,int size, int n, FILE*f), void*ptr , , int size , int n , FILE*f , .

, EOF.

int fwrite(void*ptr,int size, int n, FILE*f), void*ptr , , int size , int n , FILE*f , .

, EOF.

, . . . -:

int fprintf(FILE *f, const char*fmt,...), FILE*f , , const char*fmt ,... , .

.

int fscanf(FILE *f, const char*fmt, par1,par2,...), FILE*f , , const char*fmt , par1,par2,... , .

, .

.

int fseek(FILE *f, long off, int org), FILE *f - , long off , int org .

, . . , . <stdio.h> :

SEEK_SET ==0 ;

SEEK_CUR==1 ;

SEEK_END ==2 .

0, , .

. , . , .

void del(char *filename)

{//

FILE *f;//

FILE*temp;//

//

f=fopen(filename,rb);

//

temp=fopen(temp,wb)

student a;//

//

for(long i=0; fread(&a,sizeof(student),1,f);i++)

if(i!=x)//

{

//

fwrite(&a,sizeof(student)1,temp);

}

else

{

cout<<a<<" - is deleting...";

}

fclose(f);//

fclose(temp); //

remove(filename);//

rename(temp, filename);//

}

. , , .

, .

a a+ ( ) .

f=fopen(filename,ab);//

cout<<"\nHow many records would you add to file?";

cin>>n;

for(int i=0;i<n;i++)

{

//

fwrite(&a,sizeof(student),1,f);//

}

fclose(f);//

 

2.3. - ++

++ / -, -. / - . - , ( , , . .)

( ),

( ),

( , ).

, , , :

,

(, ),

.

C++ <iostream.h>. :

cin - , ,

cout - , .

.

/ :

<< - ;

>> - .

:

;

;

(/);

;

.

C++ :

<ifstream.h> - ,

<ofstream.h> -

<fstream.h> - .

, . . ( ). , , , ( ()). . ->.

, , :

ifstream(const char *name, int mode = ios::in);//

ofstream(const char *name, int mode = ios::out | ios::trunc);//

fstreamCconst char *name, int mode = ios::in | ios::out);//

. , ios.

ios::in ;
ios::out ;
ios::ate , , ;
ios::app ;
ios::trunc , ;
ios::binary ;
ios::nocreate , ,
ios::noreplace , , ;

, open, , .

fstream f; // f

// ,

f.open(..\\f.dat,ios::in);

// f

fstream f (..\\f.dat,ios::in);

, cin cout. , . eof().

, 0.

, , , . , close().

// person

struct person

{

char name[20];

int age;

};

person *mas;//

fstream f("f.dat",ios::out);//

int n;

cout<<"N?";

cin>>n;

mas=new person[n];//

for(int i=0;i<n;i++)

{

cout<<"?";

// person cin

cin>>mas[i].name;

cin>>mas[i].age;

}

//

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

{

 

f<<mas[i].name;f<<"\n";

f<<mas[i].age;f<<"\n";

 

}

f.close();//

 

//

person p;

f.open("f.dat",ios::in);//

do

{

/* person f p*/

f>>p.name;

f>>p.age;

// ,

if (f.eof())break;

//

cout<<p.name<<" "<<p.age<<"\n";

 

}while(!f.eof());

f.close();//

 

  1. - .
  2. .
  3. .
  4. .
  5. .
  6. - ++ .
  7. .
  8. .
  9. .
  10. .
  "": - , , ; - ; - (3); - .   .   K
  "": - , , ; - - ; - .   K
  "": - ; - ; - ; - .   , .  
  "": - , , ; - ; - ; - .   .   N
  "": - , , ; - ; - ; - .   .   K
  "": - , , ; - ; - ; - (, , , ).   , 2 .   K
  "": - , , ; - ; - ; - .   , .  
  "": - , , ; - ; - ; - .   N
  "": - , , ; - ; - ; - .   .   K
  "": - ; - ; - ; - .   .   K
  "DVD-": - ; - ; - ; - .   .  
  "DVD- ": - ; - ; - ; - .   .   N
  " ": - ; - ; - ; - .   .   K
  "": - ; - ; - ; - .   .   K
  "": - ; - ; - ; - .   , .  
  " ": - , , ; - ; - ; - .   .   N
  "": - ; - ; - ; - .   , .   K
  "": - ; - ; - ; - .   .   K
  "": - ; - ; - ; - .   , N .  
  "": - ; - ; - ; - $.   .   N
  "": - ; - ; - ; - .   K
  " ": - , , ; - ; - ; - .   .   K
  1. "": - ; - ; - ; - .   , .  
  "": - , , ; - ; - ; - 3 .   , .   N
  "": - , , ; - ; - ; - .   N

  1. ( ).
  2. .
  3. main().
  4. .

 





:


: 2016-12-06; !; : 1305 |


:

:

,
==> ...

1694 - | 1461 -


© 2015-2024 lektsii.org - -

: 0.38 .