SlideShare a Scribd company logo
1 of 28
S.AZHAGARAMMAL M.SC (info tech)
NADAR SARASWATHI COLLEGE OF ARTS AND
SCIENCE
 A files is a collection of related data
stored
In a particular area on the disk.
 The file two associated pointers
known as the file pointers.
 Each time an input or output
pointer operation takes place, the
appropriate pointer is
automatically advanced.
 When wee open a file in read-only mode, the
input pointer is automatically set the
beginning so to that we can read the from
the start.
 File is opened in ‘append’ mode.
 This moves the output pointer to the end of
the file.
Open for reading only
input pointer
Open in append mode
(for writing more data)
output pointer
Open for writing only Output pointer
output pointer
H E L L O W O R L D
H E L L O W O R L D
 This is possible only if we can take control of
the movement of the file pointers ourselves.
•Seekg() Moves get pointer (input) to a specified location.
•Seekp() Moves put pointer (output) to a specified location.
•tellg() Gives the pointer position of the get pointer.
•tellp() Give the current position of the put pointer.
infile.seekg(10);
The bytes in a file are numbered beginning
from zero.
Consider the following statement:
Ofstream fileout;
Fileout.open(“hello”,ios::app);
Int p=fileout.tellp();
 We have just now how move a file pointer to a
desired location using the ‘seek’ functions.
start file end
outfile.seek(m );
m bytes
file pointer
 The parameter offset represent the
number of bytes the file pointer is to be
moved from the location specified by the
parameter reposition.
• ios::beg start of the file
• ios::cur current position of the pointer
• ios::end End of the file
 One pair of function put() and get() are
designed for handling a single character at
a time.
 Another pair of functions, write() and
read(), are designed to write and read
blocks of binary data.
 The function put() writes a single character to
the associated stream.
 Similarly the function get() reads a single
character from the associated stream.
 To the file using the put() function in a
 It uses the function get() to fetch function file
and condition.
forloop
End-
of-file
#include <iostream.h>
#include <fstream.h>
#include <string.h>
int main()
{
Char string[80];
Cout<<“enter a stringn”;
Cin>>string;
int len =strlen (string);
fsteam.open(“TEXT”,ios::in | ios:: out);
for(int 1=0; i<len; i++)
file.seekg(0);
Char ch;
While(file)
{
file.get(ch);
Cout<< ch;
}
Return 0;
}
enter a string
Cobol_programming input
Cobol programming output
 The function write() and read(), unlike the
function put() and get(), handle the data in
binary form.
 The an in value 2594 is stored in the binary
and character formats.
 But 4 digit int will take four bytes to store it
in the character form.
Binary format 2 bytes
character format
h ft
4 bytes
00001010 0010010
2 5 9 4
 The binary format is more accurate for
storing the numbers as they are stored in
the exact internal representation.
The binary input and output:
vvvvv,
infile. read ((char *) & v, sizeof (v);
outfile .write ((char *) & v, sizeof (v);
 The first is the address of the variable v, and
the second is the length of that variable in
bytes.
 The address of the variable must be type
char*
 The two function are used to save an array
float number display in screen.
 The I/O system of c is that it cannot handle
user-defined data types such as class
object.
 The binary input and output functions
read() and write() are designed to do
exactly this job.
 The function write() copies a class object
from memory byte by byte with no
conversion.
 The length of the object is obtained using the
sizeof operator.
 The program uses ‘for’ loop for reading and
writing object.
 In case the length of the file is not known we can
determine the file-size in terms of objects with
the help of the file pointer function and use it in
the ‘for’ loop or we many use while(file) test
approach to decide the end of the file.
 The length of the object is obtained using the
sizeof operator.
 The program uses ‘for’ loop for reading and
writing object.
 In case the length of the file is not known we can
determine the file-size in terms of objects with
the help of the file pointer function and use it in
the ‘for’ loop or we many use while(file) test
approach to decide the end of the file.
 Updating is a routine in the maintenance of
any data file.
o Displaying the contents of a file.
o Modifying an existing item.
o Adding a new item.
o Deleting an existing
In such cases, the size of each object can be
obtained using the statement:
int object_length= sizeof(object);
The, the location of a desired object say
the object may be follows:
int location = m * object_length;
The location gives the bytes number of
the first of the mth object.
File pointer to each this bytes with the
help of seekg() or seekp().
 The program uses the “STOCK DAT” file
created using program.
operation on the file:
1. Adds a new item to the file.
2. Modifies the details of an item.
3. Displays the content of the file
 The using files for reading and writing on the
assumption that everything is fine with the files
1. A file which we are attempting to open
for reading does not exist.
2. The file name for a new file may already exist.
3. We may attempt an invalid operation such as
reading past the end-of file.
4. There which we are attempting to open for
reading does not exist.
5. We may use an invalid file name.
6. We may attempt to perform an operation
when the file is not opened for that
purpose.
The c++ file stream inherits a ‘stream-state’
member from the class ios.
 These are supplied at the time of invoking the
program.
 Used to names of data files.
Examples:
c > exam data results
The first argument argc (known as argument
counter) represent the number of argument in
the command line.
The second argument argv (known as a argument
vector) is an array of char type pointers that
point to the commands line argument.
C > exam data result
The value of arge would be 3 and the
argv would be an array of three
pointer to strings as shown below:
argv[0]---> exam
argv[1]---> data
argv[2]---> result
 Note that argv[0] always represent the command that invokes the
program.
 The character pointer argv[1] and argv[2] can be used name in
file.
.....
.....
infile.open(argv[1]);s
.....
.....
outfile.open(argv[2]);
.....
......
The program create two files called ODD and EVEN using the
commands-line argument and a set of numbers in an array are
written these files.

More Related Content

What's hot

Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Edureka!
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++Vineeta Garg
 
working file handling in cpp overview
working file handling in cpp overviewworking file handling in cpp overview
working file handling in cpp overviewgourav kottawar
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Abdullah khawar
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams Ahmed Farag
 
python file handling
python file handlingpython file handling
python file handlingjhona2z
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in pythonLifna C.S
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++Shyam Gupta
 
08. handling file streams
08. handling file streams08. handling file streams
08. handling file streamsHaresh Jaiswal
 
Data file handling in python reading & writing methods
Data file handling in python reading & writing methodsData file handling in python reading & writing methods
Data file handling in python reading & writing methodskeeeerty
 

What's hot (20)

Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Data file handling
Data file handlingData file handling
Data file handling
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
Files and streams
Files and streamsFiles and streams
Files and streams
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++
 
working file handling in cpp overview
working file handling in cpp overviewworking file handling in cpp overview
working file handling in cpp overview
 
Chapter 08 data file handling
Chapter 08 data file handlingChapter 08 data file handling
Chapter 08 data file handling
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
python file handling
python file handlingpython file handling
python file handling
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
Java File I/O
Java File I/OJava File I/O
Java File I/O
 
Filehadnling
FilehadnlingFilehadnling
Filehadnling
 
Python - Lecture 8
Python - Lecture 8Python - Lecture 8
Python - Lecture 8
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in python
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
08. handling file streams
08. handling file streams08. handling file streams
08. handling file streams
 
Filehandling
FilehandlingFilehandling
Filehandling
 
Data file handling in python reading & writing methods
Data file handling in python reading & writing methodsData file handling in python reading & writing methods
Data file handling in python reading & writing methods
 

Similar to working with files

Files in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceFiles in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceanuvayalil5525
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Rex Joe
 
File handling in_c
File handling in_cFile handling in_c
File handling in_csanya6900
 
File management in C++
File management in C++File management in C++
File management in C++apoorvaverma33
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handlingDeepak Singh
 
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugevsol7206
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
 
DFH PDF-converted.pptx
DFH PDF-converted.pptxDFH PDF-converted.pptx
DFH PDF-converted.pptxAmitKaur17
 
File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C ProgrammingRavindraSalunke3
 

Similar to working with files (20)

Files in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceFiles in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for reference
 
File Handling
File HandlingFile Handling
File Handling
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
Files in c++
Files in c++Files in c++
Files in c++
 
FILE HANDLING.pptx
FILE HANDLING.pptxFILE HANDLING.pptx
FILE HANDLING.pptx
 
7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
File management in C++
File management in C++File management in C++
File management in C++
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handling
 
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
 
Data file handling
Data file handlingData file handling
Data file handling
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
cpp-file-handling
cpp-file-handlingcpp-file-handling
cpp-file-handling
 
Cpp file-handling
Cpp file-handlingCpp file-handling
Cpp file-handling
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
Python-FileHandling.pptx
Python-FileHandling.pptxPython-FileHandling.pptx
Python-FileHandling.pptx
 
DFH PDF-converted.pptx
DFH PDF-converted.pptxDFH PDF-converted.pptx
DFH PDF-converted.pptx
 
Programming in C
Programming in CProgramming in C
Programming in C
 
File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C Programming
 

More from SangeethaSasi1 (20)

L4 multiplexing &amp; multiple access 16
L4 multiplexing &amp; multiple access 16L4 multiplexing &amp; multiple access 16
L4 multiplexing &amp; multiple access 16
 
Image processing using matlab
Image processing using matlab Image processing using matlab
Image processing using matlab
 
Mc ppt
Mc pptMc ppt
Mc ppt
 
Mc ppt
Mc pptMc ppt
Mc ppt
 
Dip pppt
Dip ppptDip pppt
Dip pppt
 
Web techh
Web techhWeb techh
Web techh
 
Web tech
Web techWeb tech
Web tech
 
Vani wt
Vani wtVani wt
Vani wt
 
Vani dbms
Vani dbmsVani dbms
Vani dbms
 
Hema wt (1)
Hema wt (1)Hema wt (1)
Hema wt (1)
 
Hema rdbms
Hema rdbmsHema rdbms
Hema rdbms
 
Web tech
Web techWeb tech
Web tech
 
Web tech
Web techWeb tech
Web tech
 
Dbms
DbmsDbms
Dbms
 
Vani
VaniVani
Vani
 
Hema se
Hema seHema se
Hema se
 
Software
SoftwareSoftware
Software
 
Operating system
Operating systemOperating system
Operating system
 
Dataminng
DataminngDataminng
Dataminng
 
System calls
System callsSystem calls
System calls
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 

working with files

  • 1. S.AZHAGARAMMAL M.SC (info tech) NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE
  • 2.  A files is a collection of related data stored In a particular area on the disk.
  • 3.  The file two associated pointers known as the file pointers.  Each time an input or output pointer operation takes place, the appropriate pointer is automatically advanced.
  • 4.  When wee open a file in read-only mode, the input pointer is automatically set the beginning so to that we can read the from the start.  File is opened in ‘append’ mode.  This moves the output pointer to the end of the file.
  • 5. Open for reading only input pointer Open in append mode (for writing more data) output pointer Open for writing only Output pointer output pointer H E L L O W O R L D H E L L O W O R L D
  • 6.  This is possible only if we can take control of the movement of the file pointers ourselves. •Seekg() Moves get pointer (input) to a specified location. •Seekp() Moves put pointer (output) to a specified location. •tellg() Gives the pointer position of the get pointer. •tellp() Give the current position of the put pointer.
  • 7. infile.seekg(10); The bytes in a file are numbered beginning from zero. Consider the following statement: Ofstream fileout; Fileout.open(“hello”,ios::app); Int p=fileout.tellp();
  • 8.  We have just now how move a file pointer to a desired location using the ‘seek’ functions. start file end outfile.seek(m ); m bytes file pointer
  • 9.  The parameter offset represent the number of bytes the file pointer is to be moved from the location specified by the parameter reposition. • ios::beg start of the file • ios::cur current position of the pointer • ios::end End of the file
  • 10.  One pair of function put() and get() are designed for handling a single character at a time.  Another pair of functions, write() and read(), are designed to write and read blocks of binary data.
  • 11.  The function put() writes a single character to the associated stream.  Similarly the function get() reads a single character from the associated stream.  To the file using the put() function in a  It uses the function get() to fetch function file and condition. forloop End- of-file
  • 12. #include <iostream.h> #include <fstream.h> #include <string.h> int main() { Char string[80]; Cout<<“enter a stringn”; Cin>>string; int len =strlen (string); fsteam.open(“TEXT”,ios::in | ios:: out); for(int 1=0; i<len; i++) file.seekg(0); Char ch; While(file) { file.get(ch); Cout<< ch; } Return 0; }
  • 13. enter a string Cobol_programming input Cobol programming output
  • 14.  The function write() and read(), unlike the function put() and get(), handle the data in binary form.  The an in value 2594 is stored in the binary and character formats.  But 4 digit int will take four bytes to store it in the character form.
  • 15. Binary format 2 bytes character format h ft 4 bytes 00001010 0010010 2 5 9 4
  • 16.  The binary format is more accurate for storing the numbers as they are stored in the exact internal representation. The binary input and output: vvvvv, infile. read ((char *) & v, sizeof (v); outfile .write ((char *) & v, sizeof (v);
  • 17.  The first is the address of the variable v, and the second is the length of that variable in bytes.  The address of the variable must be type char*  The two function are used to save an array float number display in screen.
  • 18.  The I/O system of c is that it cannot handle user-defined data types such as class object.  The binary input and output functions read() and write() are designed to do exactly this job.  The function write() copies a class object from memory byte by byte with no conversion.
  • 19.  The length of the object is obtained using the sizeof operator.  The program uses ‘for’ loop for reading and writing object.  In case the length of the file is not known we can determine the file-size in terms of objects with the help of the file pointer function and use it in the ‘for’ loop or we many use while(file) test approach to decide the end of the file.
  • 20.  The length of the object is obtained using the sizeof operator.  The program uses ‘for’ loop for reading and writing object.  In case the length of the file is not known we can determine the file-size in terms of objects with the help of the file pointer function and use it in the ‘for’ loop or we many use while(file) test approach to decide the end of the file.
  • 21.  Updating is a routine in the maintenance of any data file. o Displaying the contents of a file. o Modifying an existing item. o Adding a new item. o Deleting an existing
  • 22. In such cases, the size of each object can be obtained using the statement: int object_length= sizeof(object); The, the location of a desired object say the object may be follows: int location = m * object_length; The location gives the bytes number of the first of the mth object. File pointer to each this bytes with the help of seekg() or seekp().
  • 23.  The program uses the “STOCK DAT” file created using program. operation on the file: 1. Adds a new item to the file. 2. Modifies the details of an item. 3. Displays the content of the file
  • 24.  The using files for reading and writing on the assumption that everything is fine with the files 1. A file which we are attempting to open for reading does not exist. 2. The file name for a new file may already exist. 3. We may attempt an invalid operation such as reading past the end-of file.
  • 25. 4. There which we are attempting to open for reading does not exist. 5. We may use an invalid file name. 6. We may attempt to perform an operation when the file is not opened for that purpose. The c++ file stream inherits a ‘stream-state’ member from the class ios.
  • 26.  These are supplied at the time of invoking the program.  Used to names of data files. Examples: c > exam data results The first argument argc (known as argument counter) represent the number of argument in the command line. The second argument argv (known as a argument vector) is an array of char type pointers that point to the commands line argument.
  • 27. C > exam data result The value of arge would be 3 and the argv would be an array of three pointer to strings as shown below: argv[0]---> exam argv[1]---> data argv[2]---> result
  • 28.  Note that argv[0] always represent the command that invokes the program.  The character pointer argv[1] and argv[2] can be used name in file. ..... ..... infile.open(argv[1]);s ..... ..... outfile.open(argv[2]); ..... ...... The program create two files called ODD and EVEN using the commands-line argument and a set of numbers in an array are written these files.