Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
4 views
unit 5 file handling
The truth of cpp
Uploaded by
pdp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save unit 5 file handling For Later
Download
Save
Save unit 5 file handling For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
4 views
unit 5 file handling
The truth of cpp
Uploaded by
pdp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save unit 5 file handling For Later
Carousel Previous
Carousel Next
Save
Save unit 5 file handling For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 4
Search
Fullscreen
) oN P.R. Pote Patil 8203: OBJECT ORIENTED ay College of Engineering & PROGRAMMING FOR PROBLEM e Management, Amravati SOLVING ‘An Autonomous Institue Ailiated wo Sant Gadge Baba Amravati University C++ Stream Clas * InC++ stream refers to the stream of characters that are transferred between the program thread andi/o. = Stream classes in C++ are used to input and output operations on files and io devices. ‘These classes have specific features and to handle input and output of the program. ‘+ The iostream.h library holds all the stream classes in the C++ programming language. ios class ~ This class is the base class for all stream classes. The streams can be input or output streams. ‘This class defines members that are independent of how the templates of the class are defined. ostream class ~ The ostream class handles the output stream in c++ programming language. These output stream objects are used to write data as a sequence of characters on the screen. cout and puts handle the out streams in c++ programming language. Example 1: #include
using namespace std; int main0{ cout<<"This output is printed on screen"; } Output: This output is printed on screen Example 2: #include
using namespace std; int main({ puts("This output is printed using puts’ } Output: This output is printed using puts Dr. Zeeshan I. Khan, Assistant Professor, Dept. of CSE [Contact: 8380008700, Email:
[email protected]
]a) ie | P.R. Pote Patil ©8203: OBJECT ORIENTED omy College of Engineering & PROGRAMMING FOR PROBLEM i Management, Amravati SOLVING ‘An Autonomous Institue Ailiated wo Sant Gadge Baba Amravati University istream Class - The istream class handles the input stream in c++ programming language. These input stream objects are used to read and interpret the input as a sequence of characters. The cin handles the input. Example 1: #include
using namespace std; int main(( int no; cout<<"Enter a number"; cin>>no; cout<<"Number entered using cin is "<
using namespace sid; int main char ch{10]; puts("Enter a character array"); gets(ch); puts("The character array entered using gets is : puts(ch); } Output: Enter a character array thdgt ‘The character array entered using gets is : thdgt Dr. Zeeshan I. Khan, Assistant Professor, Dept. of CSE [Contact: 8380008700, Email:
[email protected]
]a) ae P.R. Pote Patil €S203: OBJECT ORIENTED College of Engineering & PROGRAMMING FOR PROBLEM Management, Amravati SOLVING ‘An Autonomous Institue Ailiated wo Sant Gadge Baba Amravati University Opening, Closing, Reading & Writing a File Files play an important role in programming. It allows storage of data permanently. The C++ language provides a mechanism to store the output of a program in a file and browse from a file on the disk. This mechanism is termed file handling. In order to perform file handling, some general functions which are used are as follows: oR ep open(): This function helps to create a file and open the file in different modes, like input operations, output operations, binary mode, etc. close(): This function helps to close an existing file. get(): This function helps to read a single character from the file. put(): This function helps to write a single character in the file. read(): This function helps to read data from a file. write(): This function helps us to write data into a file. For Example #include
#finclude
using namespace std; int main { char data[100}; ofstream outtile; outfile.open("trial.txt"); cout << "Writing to the file" << endl; cout << "Enter your name: "; cin.getline(data, 100); outfile << data << endl; outfile.close(); ifstream infile; infile.open("trial.txt"); cout << "Reading from the file"<< endl; infile >> data; cout << data << endl; infile.closeQ; return 0; } Output: Writing to the file Enter your name: Hello Reading from the file Hello Dr. Zeeshan I. Khan, Assistant Professor, Dept. of CSE [Contact: 8380008700, Email:
[email protected]
]) oN P.R. Pote Patil ay Collage of Engineering & u Management, Amravati ‘An Autonomous Institue Ailiated wo Sant Gadge Baba Amravati University End of File in C++ The eof() method of ios class in C++ is used to check if the stream is has raised any EOF (End Of File) error. ©8203: OBJECT ORIENTED PROGRAMMING FOR PROBLEM SOLVING It means that this function will check if this stream has its eofbit set. Syntax: bool eof() con: Example: #tinclude
using namespace std; int main { stringstream ss; bool isEOF = ss.cof(); cout << "is stream eof: "<< isEOF << endl; ss.clear(ss.eotbit); isEOF = ss.eof(); cout << "is stream eof: "<< isEOF << endl; return 0; } Output: is stream eof: 0 is stream eof: 1 Dr. Zeeshan I. Khan, Assistant Professor, Dept. of CSE [Contact: 8380008700, Email:
[email protected]
]
You might also like
File Handling PDF
PDF
No ratings yet
File Handling PDF
15 pages
Topic: Concept of Stream: Course Name
PDF
No ratings yet
Topic: Concept of Stream: Course Name
17 pages
C++ Prog and Appl
PDF
No ratings yet
C++ Prog and Appl
5 pages
Oop Notes Unit 4
PDF
No ratings yet
Oop Notes Unit 4
12 pages
Unit - V - OOPS
PDF
No ratings yet
Unit - V - OOPS
81 pages
IT 304 OOPM Unit V - 1693892221
PDF
No ratings yet
IT 304 OOPM Unit V - 1693892221
10 pages
Introduction To Object-Oriented Programming COMP2011: File I/O
PDF
No ratings yet
Introduction To Object-Oriented Programming COMP2011: File I/O
11 pages
Oop Unit-V
PDF
No ratings yet
Oop Unit-V
69 pages
Unit-V File Operations
PDF
No ratings yet
Unit-V File Operations
47 pages
LAB 15 - Oop
PDF
No ratings yet
LAB 15 - Oop
14 pages
For: COP 3330. Object Oriented Programming (Using C++)
PDF
No ratings yet
For: COP 3330. Object Oriented Programming (Using C++)
11 pages
C++ Input Output
PDF
No ratings yet
C++ Input Output
4 pages
C Day-14
PDF
No ratings yet
C Day-14
13 pages
Unit-IV Oop Part-i Rbk
PDF
No ratings yet
Unit-IV Oop Part-i Rbk
70 pages
Mit Opencourseware: 6.096 Introduction To C++
PDF
No ratings yet
Mit Opencourseware: 6.096 Introduction To C++
6 pages
OOP_L1_L001_Exp9
PDF
No ratings yet
OOP_L1_L001_Exp9
21 pages
Module Five
PDF
No ratings yet
Module Five
18 pages
C++Lec6 Streams and Files
PDF
No ratings yet
C++Lec6 Streams and Files
30 pages
File 1
PDF
No ratings yet
File 1
25 pages
C++ Notes Unit 5
PDF
No ratings yet
C++ Notes Unit 5
14 pages
EEB 334 - Chapter 6
PDF
No ratings yet
EEB 334 - Chapter 6
29 pages
CPP Chapter 7
PDF
No ratings yet
CPP Chapter 7
27 pages
C++ Unit V
PDF
No ratings yet
C++ Unit V
14 pages
Topic:: Files & I/O
PDF
No ratings yet
Topic:: Files & I/O
30 pages
unit4 (1)
PDF
No ratings yet
unit4 (1)
36 pages
Unit6 Notes
PDF
No ratings yet
Unit6 Notes
26 pages
C++ Unit V
PDF
No ratings yet
C++ Unit V
14 pages
Oop Unit 4
PDF
No ratings yet
Oop Unit 4
11 pages
Oop Chapter 05
PDF
No ratings yet
Oop Chapter 05
15 pages
File Handling in C++: By: Haya Majid Qureshi BS (CS) - II
PDF
No ratings yet
File Handling in C++: By: Haya Majid Qureshi BS (CS) - II
28 pages
Chapter Four: File I/O
PDF
No ratings yet
Chapter Four: File I/O
35 pages
Console I/O Operations Console I/O Operations
PDF
No ratings yet
Console I/O Operations Console I/O Operations
66 pages
Unit 4 L11
PDF
No ratings yet
Unit 4 L11
85 pages
Programming Fundamentals in C++: Practical#14)
PDF
No ratings yet
Programming Fundamentals in C++: Practical#14)
27 pages
Unit 5 Part1 - OOP
PDF
No ratings yet
Unit 5 Part1 - OOP
9 pages
Class Bfs 12091159031978
PDF
No ratings yet
Class Bfs 12091159031978
10 pages
E Balagurusamy: File I/O With Streams
PDF
No ratings yet
E Balagurusamy: File I/O With Streams
8 pages
Unit V Streams and Exception Handling
PDF
No ratings yet
Unit V Streams and Exception Handling
49 pages
PPT10
PDF
No ratings yet
PPT10
52 pages
Data File Handling - NR
PDF
No ratings yet
Data File Handling - NR
30 pages
Random Access 5THUNIT 2
PDF
No ratings yet
Random Access 5THUNIT 2
30 pages
Stream Classes
PDF
No ratings yet
Stream Classes
19 pages
File Handling
PDF
No ratings yet
File Handling
56 pages
Introduction to C++ Programming(BPLCK205D)_Class PPT_Module-4
PDF
No ratings yet
Introduction to C++ Programming(BPLCK205D)_Class PPT_Module-4
42 pages
Chapter 6b
PDF
No ratings yet
Chapter 6b
34 pages
Unit 5 Module 2 Data Hierarchy in Object
PDF
No ratings yet
Unit 5 Module 2 Data Hierarchy in Object
27 pages
In&out_to file
PDF
No ratings yet
In&out_to file
4 pages
CH - 11 Console
PDF
No ratings yet
CH - 11 Console
21 pages
File Handling in C
PDF
No ratings yet
File Handling in C
17 pages
Screenshot 2024-06-22 at 11.52.59 AM
PDF
No ratings yet
Screenshot 2024-06-22 at 11.52.59 AM
8 pages
Module 4 C++ Notes
PDF
No ratings yet
Module 4 C++ Notes
10 pages
Unit_6
PDF
No ratings yet
Unit_6
59 pages
Master C++ 8
PDF
No ratings yet
Master C++ 8
16 pages
Unit 4
PDF
No ratings yet
Unit 4
50 pages
5 - Input-Output Streams as an Introduction
PDF
No ratings yet
5 - Input-Output Streams as an Introduction
26 pages
Oop Unit V
PDF
No ratings yet
Oop Unit V
18 pages
Basics Library in C++
PDF
No ratings yet
Basics Library in C++
3 pages
Chapter 5 Introduction to Knowledge
PDF
No ratings yet
Chapter 5 Introduction to Knowledge
17 pages
23 jan 2025 rea
PDF
No ratings yet
23 jan 2025 rea
4 pages
space exploration of the w galaxy
PDF
No ratings yet
space exploration of the w galaxy
18 pages
unit 6 Templates and exceptions
PDF
No ratings yet
unit 6 Templates and exceptions
5 pages
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
File Handling PDF
PDF
File Handling PDF
Topic: Concept of Stream: Course Name
PDF
Topic: Concept of Stream: Course Name
C++ Prog and Appl
PDF
C++ Prog and Appl
Oop Notes Unit 4
PDF
Oop Notes Unit 4
Unit - V - OOPS
PDF
Unit - V - OOPS
IT 304 OOPM Unit V - 1693892221
PDF
IT 304 OOPM Unit V - 1693892221
Introduction To Object-Oriented Programming COMP2011: File I/O
PDF
Introduction To Object-Oriented Programming COMP2011: File I/O
Oop Unit-V
PDF
Oop Unit-V
Unit-V File Operations
PDF
Unit-V File Operations
LAB 15 - Oop
PDF
LAB 15 - Oop
For: COP 3330. Object Oriented Programming (Using C++)
PDF
For: COP 3330. Object Oriented Programming (Using C++)
C++ Input Output
PDF
C++ Input Output
C Day-14
PDF
C Day-14
Unit-IV Oop Part-i Rbk
PDF
Unit-IV Oop Part-i Rbk
Mit Opencourseware: 6.096 Introduction To C++
PDF
Mit Opencourseware: 6.096 Introduction To C++
OOP_L1_L001_Exp9
PDF
OOP_L1_L001_Exp9
Module Five
PDF
Module Five
C++Lec6 Streams and Files
PDF
C++Lec6 Streams and Files
File 1
PDF
File 1
C++ Notes Unit 5
PDF
C++ Notes Unit 5
EEB 334 - Chapter 6
PDF
EEB 334 - Chapter 6
CPP Chapter 7
PDF
CPP Chapter 7
C++ Unit V
PDF
C++ Unit V
Topic:: Files & I/O
PDF
Topic:: Files & I/O
unit4 (1)
PDF
unit4 (1)
Unit6 Notes
PDF
Unit6 Notes
C++ Unit V
PDF
C++ Unit V
Oop Unit 4
PDF
Oop Unit 4
Oop Chapter 05
PDF
Oop Chapter 05
File Handling in C++: By: Haya Majid Qureshi BS (CS) - II
PDF
File Handling in C++: By: Haya Majid Qureshi BS (CS) - II
Chapter Four: File I/O
PDF
Chapter Four: File I/O
Console I/O Operations Console I/O Operations
PDF
Console I/O Operations Console I/O Operations
Unit 4 L11
PDF
Unit 4 L11
Programming Fundamentals in C++: Practical#14)
PDF
Programming Fundamentals in C++: Practical#14)
Unit 5 Part1 - OOP
PDF
Unit 5 Part1 - OOP
Class Bfs 12091159031978
PDF
Class Bfs 12091159031978
E Balagurusamy: File I/O With Streams
PDF
E Balagurusamy: File I/O With Streams
Unit V Streams and Exception Handling
PDF
Unit V Streams and Exception Handling
PPT10
PDF
PPT10
Data File Handling - NR
PDF
Data File Handling - NR
Random Access 5THUNIT 2
PDF
Random Access 5THUNIT 2
Stream Classes
PDF
Stream Classes
File Handling
PDF
File Handling
Introduction to C++ Programming(BPLCK205D)_Class PPT_Module-4
PDF
Introduction to C++ Programming(BPLCK205D)_Class PPT_Module-4
Chapter 6b
PDF
Chapter 6b
Unit 5 Module 2 Data Hierarchy in Object
PDF
Unit 5 Module 2 Data Hierarchy in Object
In&out_to file
PDF
In&out_to file
CH - 11 Console
PDF
CH - 11 Console
File Handling in C
PDF
File Handling in C
Screenshot 2024-06-22 at 11.52.59 AM
PDF
Screenshot 2024-06-22 at 11.52.59 AM
Module 4 C++ Notes
PDF
Module 4 C++ Notes
Unit_6
PDF
Unit_6
Master C++ 8
PDF
Master C++ 8
Unit 4
PDF
Unit 4
5 - Input-Output Streams as an Introduction
PDF
5 - Input-Output Streams as an Introduction
Oop Unit V
PDF
Oop Unit V
Basics Library in C++
PDF
Basics Library in C++
Chapter 5 Introduction to Knowledge
PDF
Chapter 5 Introduction to Knowledge
23 jan 2025 rea
PDF
23 jan 2025 rea
space exploration of the w galaxy
PDF
space exploration of the w galaxy
unit 6 Templates and exceptions
PDF
unit 6 Templates and exceptions