0% found this document useful (0 votes)
83 views2 pages

C++ File Updation

The fopen function is used to open a file in C++. It takes a file name and access mode as arguments and returns a pointer to a FILE structure if successful or NULL if unsuccessful. The access mode specifies whether the file should be opened for reading, writing, appending, or updating and whether in text or binary mode. Common errno return values on failure include permission denied, invalid access mode, and file/path not found.

Uploaded by

Saurav Naruka
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
83 views2 pages

C++ File Updation

The fopen function is used to open a file in C++. It takes a file name and access mode as arguments and returns a pointer to a FILE structure if successful or NULL if unsuccessful. The access mode specifies whether the file should be opened for reading, writing, appending, or updating and whether in text or binary mode. Common errno return values on failure include permission denied, invalid access mode, and file/path not found.

Uploaded by

Saurav Naruka
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 2

C++ Now FILE Stream fopen Function

Usage:
The fopen function is used to open a file (identified by FILE structure).

Prototype:
FILE * fopen (const char * FileName, const char * Access);

Arguments:
Filename
Operating system name of the file, including path if necessary.

Access
One of the following character strings:

r
Open for reading (existing file only)

rb
Open for reading (existing file only) in binary mode

rt
Open for reading (existing file only) in text mode

r+
Open for update (existing file only)

rb+
Open for update (existing file only) in binary mode

rt+
Open for update (existing file only) in text mode

w
Open (or create) for writing (and delete any previous data)

wb
Open (or create) for writing (and delete any previous data) in binary mode

wt
Open (or create) for writing (and delete any previous data) in text mode

w+
Open (or create) for update (and delete any previous data)

wb+
Open (or create) for update (and delete any previous data) in binary mode

wt+
Open (or create) for update (and delete any previous data) in text mode

a
Open (or create) for append (and keep any previous data)

ab
Open (or create) for append (and keep any previous data) in binary mode

at
Open (or create) for append (and keep any previous data) in text mode

a+
Open (or create) for append update (and keep any previous data)

ab+
Open (or create) for append update (and keep any previous data) in binary mode

at+
Open (or create) for append update (and keep any previous data) in text mode

Header Files:
stdio.h
(fopen)

errno.h
(errno values)

Returns:
> 0
Pointer to an open FILE structure

NULL
Failure

Side Effect:
errno
Iff the open fails, the global variable errno is set to error code

EACCES
Permission denied

EINVACC
Invalid access mode

EMFILE
No file handle available

ENOENT
File or path not found

Example:
#include <stdio.h> . . . FILE * Account_Master; . . . Account_Master = fopen ("E:\DATA\ACCOUNTS.DAT", "ab+"); if (Account_Master == NULL) printf ("Open failed."); else printf ("Open succeeded.");

You might also like