SlideShare a Scribd company logo
1 of 13
Presentation:
Topic: File Handling
Subject: Intro to Programming
Presented to: Sir Fasee Ullah
Presented by: Waqar Ali
Submission date: 21- 05 - 2014
Class: BSSE ( A )
Department: Software Engineering
C++
 File Handling
 Reading File
 Writing on File
 We need to know:
• how to "connect" file to program
• how to tell the program to read
data
• how to tell the program to write
data
(1) Header File : #include<fstream>
(2) Declaration
(3) Open the file
(4) Process the File
(5) Close the File
 Classes:
 ifstream (input only)
 ofstream (output only)
 Uses:
For Reading a file We use a function
“ ifstream ”
While for Writing on file we use a function
called “ ofstream ”
READ FROM FILE WRITING ON FILE
#include<iostream>
#include<fstream>
using namespace std:
void main()
{
ofstream abc;
abc.open(“file_name”);
Cout<<“ur_msg”;
abc>>name;
abc.close();
getch();
}
#include<iostream>
#include<fstream>
using namespace std:
void main()
{
datatype Name;
ifstream file_name;
file_name.open(“ ”)
file_name<<“ ”<<endl;
file_name.close( );
getch( );
}
Writing on file
#include<iostream>
#include<conio.h>
#include<fstream> //file stream
using namespace std;
int main()
{
ofstream cr ; //class file name
cr.open("info.txt"); //Create a file ( open )
cr<<"File: "; //writing on files
cr<<"nName: ";
cr<<"nReg: ";
cr<<"nDepartment: ";
cr.close(); // closing file
getch();
}
Reading from File
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
string line;
ifstream file;
file.open("info.txt");
getline(file,line);
cout<<line<<endl;
getline(file,line);
cout<<line<<endl;
getline(file,line);
cout<<line<<endl;
getline(file,line);
cout<<line<<endl;
file.close();
getch();
}
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
ofstream cr;
cr.open("info.txt");
cr<<"File: "<<endl;
cr<<"Name: "<<endl;
cr<<"Reg: "<<endl;
cr<<"Department: "<<endl;
cr.close();
 string line;
 ifstream rc;
 rc.open("info.txt");

 getline(rc,line);
 cout<<line;
 cout<<"Student info"<<endl;
 getline(rc,line);

 cout<<line;
 cout<<"Waqar Ali"<<endl;
 getline(rc,line);

 cout<<line;
 cout<<"5509"<<endl;
 getline(rc,line);

 cout<<line;
 cout<<"Software Engineering"<<endl;
 getline(rc,line);
 rc.close();
 getch();
 }
File Handling

More Related Content

What's hot

basics of file handling
basics of file handlingbasics of file handling
basics of file handling
pinkpreet_kaur
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
sotlsoc
 

What's hot (20)

File handling
File handlingFile handling
File handling
 
Python file handling
Python file handlingPython file handling
Python file handling
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
File handling and Dictionaries in python
File handling and Dictionaries in pythonFile handling and Dictionaries in python
File handling and Dictionaries in python
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary fileCBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Files
FilesFiles
Files
 
File handling
File handlingFile handling
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
C filesC files
C files
 
File handling
File handlingFile handling
File handling
 
17 files and streams
17 files and streams17 files and streams
17 files and streams
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
File management
File managementFile management
File management
 
Data file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing filesData file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing files
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Files and file objects (in Python)
Files and file objects (in Python)Files and file objects (in Python)
Files and file objects (in Python)
 

Viewers also liked

Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
Introduction to trees
 Introduction to trees Introduction to trees
Introduction to trees
priya_trehan
 
Data file handling
Data file handlingData file handling
Data file handling
TAlha MAlik
 
Chapeuzinho vermelho turma da mônica
Chapeuzinho vermelho  turma da mônicaChapeuzinho vermelho  turma da mônica
Chapeuzinho vermelho turma da mônica
maraanjo
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
Charndeep Sekhon
 

Viewers also liked (20)

Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
 
Introduction to trees
 Introduction to trees Introduction to trees
Introduction to trees
 
pointer, structure ,union and intro to file handling
 pointer, structure ,union and intro to file handling pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Generic programming
Generic programmingGeneric programming
Generic programming
 
John Davies: "High Performance Java Binary" from JavaZone 2015
John Davies: "High Performance Java Binary" from JavaZone 2015John Davies: "High Performance Java Binary" from JavaZone 2015
John Davies: "High Performance Java Binary" from JavaZone 2015
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IO
 
Data file handling
Data file handlingData file handling
Data file handling
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 
Java file
Java fileJava file
Java file
 
Comp102 lec 11
Comp102   lec 11Comp102   lec 11
Comp102 lec 11
 
Chapeuzinho vermelho turma da mônica
Chapeuzinho vermelho  turma da mônicaChapeuzinho vermelho  turma da mônica
Chapeuzinho vermelho turma da mônica
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++
 
Elegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and ExceptionsElegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and Exceptions
 
File handling
File handlingFile handling
File handling
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Exception handling
Exception handlingException handling
Exception handling
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
 

Similar to File Handling

Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
Rex Joe
 
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
anuvayalil5525
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
pinkpreet_kaur
 

Similar to File Handling (20)

File handling in cpp
File handling in cppFile handling in cpp
File handling in cpp
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
Session9-File Upload Security
Session9-File Upload SecuritySession9-File Upload Security
Session9-File Upload Security
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
Files in c++
Files in c++Files in c++
Files in c++
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
Files in c++
Files in c++Files in c++
Files in c++
 
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
 
working with files
working with filesworking with files
working with files
 
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
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
C-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptxC-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptx
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
 
7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
 
File management in C++
File management in C++File management in C++
File management in C++
 
File operations
File operationsFile operations
File operations
 

More from Waqar Ali (7)

Debugging by induction
Debugging by inductionDebugging by induction
Debugging by induction
 
Chapter 1 - Introduction
Chapter 1 - IntroductionChapter 1 - Introduction
Chapter 1 - Introduction
 
Project Time Management
Project Time Management Project Time Management
Project Time Management
 
Normalization
NormalizationNormalization
Normalization
 
Normalization
NormalizationNormalization
Normalization
 
Join query
Join queryJoin query
Join query
 
The Ethical and Social Enviroment
The Ethical and Social EnviromentThe Ethical and Social Enviroment
The Ethical and Social Enviroment
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

File Handling

  • 1. Presentation: Topic: File Handling Subject: Intro to Programming Presented to: Sir Fasee Ullah Presented by: Waqar Ali Submission date: 21- 05 - 2014 Class: BSSE ( A ) Department: Software Engineering
  • 2. C++
  • 3.  File Handling  Reading File  Writing on File
  • 4.  We need to know: • how to "connect" file to program • how to tell the program to read data • how to tell the program to write data
  • 5. (1) Header File : #include<fstream> (2) Declaration (3) Open the file (4) Process the File (5) Close the File
  • 6.  Classes:  ifstream (input only)  ofstream (output only)  Uses: For Reading a file We use a function “ ifstream ” While for Writing on file we use a function called “ ofstream ”
  • 7. READ FROM FILE WRITING ON FILE #include<iostream> #include<fstream> using namespace std: void main() { ofstream abc; abc.open(“file_name”); Cout<<“ur_msg”; abc>>name; abc.close(); getch(); } #include<iostream> #include<fstream> using namespace std: void main() { datatype Name; ifstream file_name; file_name.open(“ ”) file_name<<“ ”<<endl; file_name.close( ); getch( ); }
  • 8. Writing on file #include<iostream> #include<conio.h> #include<fstream> //file stream using namespace std; int main() { ofstream cr ; //class file name cr.open("info.txt"); //Create a file ( open ) cr<<"File: "; //writing on files cr<<"nName: "; cr<<"nReg: "; cr<<"nDepartment: "; cr.close(); // closing file getch(); }
  • 9.
  • 10. Reading from File #include<iostream> #include<conio.h> #include<fstream> using namespace std; int main() { string line; ifstream file; file.open("info.txt"); getline(file,line); cout<<line<<endl; getline(file,line); cout<<line<<endl; getline(file,line); cout<<line<<endl; getline(file,line); cout<<line<<endl; file.close(); getch(); }
  • 11.
  • 12. #include<iostream> #include<conio.h> #include<fstream> using namespace std; int main() { ofstream cr; cr.open("info.txt"); cr<<"File: "<<endl; cr<<"Name: "<<endl; cr<<"Reg: "<<endl; cr<<"Department: "<<endl; cr.close();  string line;  ifstream rc;  rc.open("info.txt");   getline(rc,line);  cout<<line;  cout<<"Student info"<<endl;  getline(rc,line);   cout<<line;  cout<<"Waqar Ali"<<endl;  getline(rc,line);   cout<<line;  cout<<"5509"<<endl;  getline(rc,line);   cout<<line;  cout<<"Software Engineering"<<endl;  getline(rc,line);  rc.close();  getch();  }