






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to file input and output (i/o) operations in c++ using docsity.com. Topics covered include opening and closing files, reading and writing characters using get() and put(), file positions using tellg() and tellp(), and positioning using seekg() and seekp(). Examples are given to illustrate the use of these functions.
Typology: Slides
1 / 30
This page cannot be seen from the preview
Don't miss anything!























Introduction to Programming Lecture 19
ifstream myFilePtr ; myFilePtr.open ( “myFile” , ios :: in ) ;
ios :: app ios :: trunc ios :: ate
tellp ( ) Function myFile.tellp ( ) ; Returns a whole number which tell you the position of the next character to be written in a file
For Positioning in the file seekg ( ) ; seekp ( ) ;
seekg ( ) seekg ( 10L , ios :: beg ) ; seekg (10L , ios :: cur ) ; seekg ( 10L , ios :: end ) ;
#include<fstream.h> main ( ) { int length ; ifstream inFile ( “myFile.txt” ) ; inFile.seekg ( 0L , ios :: end ) ; length = inFile.tellg ( ) ; }
Merge Method This is a text data And needs Original file Empty file To be replaced (^) NOT
seekg ( ) seekg ( 2201L , ios :: beg ) ;
OR Function A B Output 0 0 0 0 1 1 1 0 1 1 1 1
Example 2 This is an Apple This is a Sample