C++ . FILE, stdio.h. , , : , -, , , , ..
FILE * ;
:
#include<stdio.h>..............FILE *fp;2)
() ( ), FILE. .
, , : (), : . :
FILE fopen (const char* _,const char* __);
= fopen (_, _);
FILE, , NULL . ( , ).
2.
2.
mode | |
r | . ( ) 0. , fopen NULL. |
w | . filename. ( ) 0. . , , , . |
a | . . . |
r+ | ( ). 0. . |
w+ | ( ). filename. 0, . |
a+ | ( ). EOF. . |
b | . b r,w,a,r+,w+,a+. : "r+b","w+b". |
t | . t r,w,a,r+,w+,a+. : "r+t","wt". |
:
|
|
t ;
b .
:
"r+b" "rb" () ;
"r+t" "rt" .
, ( ). .
:
FILE *f = fopen (d:\\cpp\\data, rb+);
f . / .
FILE *ft; //
ft = fopen(inp_f.txt, r); // inp_f.txt
. . . , fopen() NULL, .
FILE *ft; //
if (ft = fopen(inp_f.txt, r)== NULL) //
{ < > }
else { < > }
:
, ( );
( );
( ) . .
NULL (0). , , NULL.
<stdio.h>:
void perror (const char*s);perror() , s, : , . .
1. .
#include "stdafx.h"#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ FILE *fp; if ((fp=fopen("t.txt", "r"))==NULL) // perror(" "); system("pause"); return 0;}on_load_lecture();
, . . setbuf() setvbuf() .
3) ( , , , );
|
|
4) .
, file. , DOS - : - .
:
- ;
- fclose():
int fclose (FILE *);
0 -1 .
. , , . .
:
Fcloseall(void);
(, ) , fclose().