File Handling in C - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

File Handling in C

Description:

File Handling Introduction to File Handling Data entered once, required later again Same Data to be used by others Data required again by the same program Files and ... – PowerPoint PPT presentation

Number of Views:317
Avg rating:3.0/5.0
Slides: 12
Provided by: msmjsuare
Category:
Tags: data | file | handling

less

Transcript and Presenter's Notes

Title: File Handling in C


1
File Handling in C
2
File Handling
  • Introduction to File Handling
  • Data entered once, required later again
  • Same Data to be used by others
  • Data required again by the same program
  • Files and Streams

3
Program
Output Stream
Input Stream
Files
4
I/O Streams
  • Stream Description
  • cin Standard input stream
  • cout Standard output stream
  • cerr Standard error stream

5
File i/o Streams
  • Stream Classes required for File i/o
  • ifstream
  • ofstream
  • fstream

6
ifstream
  • Input file stream Class
  • open() is a member function of the class ifstream
  • Inherited functions of ifstream class, from the
    class istream are
  • get()
  • getline()
  • read()
  • seekg()
  • tellg()

7
ofstream
  • Output file stream Class
  • open() is a member function of the class ofstream
  • Inherited functions of ofstream class, from the
    class ostream are
  • put()
  • write()
  • seekp()
  • tellp()

8
fstream
  • It supports files for simultaneous input and
    output
  • fstream is derived from
  • ifstream
  • ofstream
  • iostream
  • They are parent classes and fstream is the child
    class

9
fstream
  • Member functions of the class fstream
  • open
  • close
  • close all
  • seekg
  • seekp
  • tellg
  • tellp

10
  • //This program creates a file called
    message.dat
  • include ltfstreamgt //Required for file I/O
  • include ltiostreamgt
  • using namespace std
  • int main()
  • ofstream myfile ("message.dat")
  • if (!myfile)
  • //check if the file is opened or not
  • coutltlt"\n Cannot open this file"
  • return 1
  • myfile ltlt"When an apple fell, Newton was
    disturbed \n"
  • myfile ltlt"but, when he found that all apples
    fell, \n"
  • myfile ltlt"it was gravitation that attracts them
    down,\n"
  • myfile ltlt"he was satisfied \n"
  • myfile.close() //close the file

11
Function in C
  • Function Prototype
  • Function Call
  • Function Definition
Write a Comment
User Comments (0)
About PowerShow.com