Stream File
Stream File
A Project Report
University of Technology
By
RAMYASHREE V
USN : 2LG21CS033
Miss.Shridevi
TALAKAL, KOPPALA.
TABLE CONTENT
CERTIFICATE
ACKNOWLEDGEMENT
APPROVAL
INTRODUCTION
CLASSES OF FILE STREAM
EXAMPLE PROGRAM
BENEFITS OF FILE STREAM
CONCLUSION
REFERENCES
CERTIFICATE
This is to certify that the Seminar entitled About File Stream presented by
Ramyashree V bearing USN 2LG21CS037 of Computer Science and
Engineering has been has been completed successfully.
Ramyashree V
USN:2LG21CS033
ABSTRACT
Stream in C++ means a stream of characters that gets transferred between the
program thread and input or output. There are a number of C++ stream classes
eligible and defined which is related to the files and streams for providing input-
output operations. All the classes and structures maintaining the file and folders
with hierarchies are defined within the file with iostream.h standard library.
Classes associated with the C++ stream include ios class, istream class, and
ostream class. Class ios is indirectly inherited from the base class involving
iostream class using istream class and ostream class which is declared virtually.
Name : Ramyashree V
USN : 2LG21CS033
Section:
Date:
INTRODUCTION
In C++ the concept of the file stream is used for the reading and writing on the
file system. In very simple and technical words we can say it has ability to do
dual work which means it has of stream and if stream. So in case if the file is
not there on which we are going to write some contents then the f stream has
capability to write the contents on the file and at the same time it also allows us
to open the file and display the contents of the files. We should use this if we
know that we are going to create, read and write contents on the file.
The I/O system of C++ contains a set of classes which define the file handling
methods. These include ifstream, ofstream and fstream classes. These classes
are derived from fstream and from the corresponding iostream class. These
classes, designed to manage the disk files, are declared in fstream and
therefore we must include this file in any program that uses files.
1. ios:-
ios stands for input output stream.
This class is the base class for other classes in this class hierarchy.
This class contains the necessary facilities that are used by all the other
derived classes for input and output operations.
2. istream:-
istream stands for input stream.
This class is derived from the class ‘ios’.
This class handle input stream.
The extraction operator(>>) is overloaded in this class to handle input
streams from files to the program execution.
This class declares input functions such as get(), getline() and read().
3. ostream:-
ostream stands for output stream.
This class is derived from the class ‘ios’.
This class handle output stream.
The insertion operator(<<) is overloaded in this class to handle output
streams to files from the program execution.
This class declares output functions such as put() and write().
4. streambuf:-
This class contains a pointer which points to the buffer which is used to
manage the input and output streams.
5. fstreambase:-
This class provides operations common to the file streams. Serves as a base
for fstream, ifstream and ofstream class.
This class contains open() and close() function.
6. ifstream:-
This class provides input operations.
It contains open() function with default input mode.
Inherits the functions get(), getline(), read(), seekg() and tellg() functions
from the istream.
7. ofstream:-
This class provides output operations.
It contains open() function with default output mode.
Inherits the functions put(), write(), seekp() and tellp() functions from the
ostream.
8. fstream:-
This class provides support for simultaneous input and output operations.
Inherits all the functions from istream and ostream classes through
iostream.
9. filebuf:-
Its purpose is to set the file buffers to read and write.
We can also use file buffer member function to determine the length of the
file.
In C++, files are mainly dealt by using three classes fstream, ifstream,
ofstream available in fstream headerfile.
Below is a simple syntax for the f stream in the C++. In the below example first
we are getting or creating a file, we can give any name to file which we are
creating here. Second we are writing some contents to the file. In the same way
we can read the file content with help of the get line function in while loop.
Of stream creatMyFile(AnyFileName);
creatMyFile << Any text as contents;
fstream It is used to create files, write information to files, and read information from files.
We have already package like if stream and of stream but they can either
read and write the file, but what we do in case if we want to perform read and
write the file? So for that case we have f stream C++ package.
Here first we can create a file instance with code like “of stream of”, here
Next we can pass any name of file which we want to create like
“open(any filename);”.
Finally, we can write the contents on the file like cout << “any contents
If needed, then we can also read the contents of the file with the help of
EXAMPLE1:
Opening a File
A file must be opened before you can read from it or write to it.
Either ofstream or fstream object may be used to open a file for writing. And
ifstream object is used to open a file for reading purpose only.
Following is the standard syntax for open() function, which is a member of
fstream, ifstream, and ofstream objects.
void open(const char *filename, ios::openmode mode);
Here, the first argument specifies the name and location of the file to be opened
and the second argument of the open() member function defines the mode in
which the file should be opened.
Closing a File
When a C++ program terminates it automatically flushes all the streams, release
all the allocated memory and close all the opened files. But it is always a good
practice that a programmer should close all the opened files before program
termination.
Following is the standard syntax for close() function, which is a member of
fstream, ifstream, and ofstream objects.
void close();
Writing to a File
While doing C++ programming, you write information to a file from your
program using the stream insertion operator (<<) just as you use that operator
to output information to the screen. The only difference is that you use
an ofstream or fstream object instead of the cout object.
#include<io_stream.h>
Void main()
{
int p,q,r;
Cout<<”Enter 3 integers separated by space:\n”;
Cin>>”Sum of the”<<p<<”,”<<q<<”and”<<r<<”is=”<<(p+q+r)<<endl;
}
Advantages of C++ file stream
One of the most important things about it is, it allows us to use the
Because it has a feature where if the file does not exist instead of
CONCLUSION
C++ Stream is a very powerful and versatile functionality of the stream classes.
They provide programmers an insight for using the predefined and in build
functions by modification in the object and the standard libraries of the class for
References:
1) Object oriented programming with C++ E Balaguruswamy
2) Object oriented programming using C++ Dr. Rajiv Chopra
Hadoop
ReactJS
Data Science
Angular 7
Blockchain
Git
Machine Learning
DevOps
B.Tech / MCA
DBMS
Data Structures
DAA
Operating System
Computer Network
Compiler Design
Computer Organization
Discrete Mathematics
Ethical Hacking
Computer Graphics
Software Engineering
Web Technology
Cyber Security
Automata
C Programming
C++
Java
.Net
Python
Programs
Control System
Data Mining
Data Warehouse
Report this ad
Javatpoint Services
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more
information about given services.
o Website Designing
o Website Development
o Java Development
o PHP Development
o WordPress
o Graphic Designing
o Logo
o Digital Marketing
o On Page and Off Page SEO
o PPC
o Content Development
o Corporate Training
o Classroom and Online Training
o Data Entry
Training For College Campus
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android,
Hadoop, PHP, Web Technology and Python. Please mail your requirement
at [email protected].
Duration: 1 week to 2 week
LEARN TUTORIALS
OUR WEBSITES
Javatpoint.comHindi100.comLyricsia.comQuoteperson.comJobandplacement.com
OUR SERVICES
Website Development
Android Development
Website Designing
Digital Marketing
Summer Training
Industrial Training
CONTACT
EMAIL (OPTIONAL)
Report This Ad
X
Feedback
SPSS
Swagger
Transact-SQL
Tumblr
ReactJS
Regex
Reinforcement Learning
R Programming
RxJS
React Native
Python Pillow
Python Turtle
Keras
Preparation
Aptitude
Reasoning
Verbal Ability
Interview Questions
Company Questions
Trending Technologies
Artificial Intelligence
AWS
Selenium
Cloud Computing
Hadoop
ReactJS
Data Science
Angular 7
Blockchain
Git
Machine Learning
DevOps
B.Tech / MCA
DBMS
Compiler Design
Computer Organization
Discrete Mathematics
Ethical Hacking
Computer Graphics
Software Engineering
Web Technology
Cyber Security
Automata
C Programming
C++
Java
.Net
Python
Programs
Control System
Data Mining
Data Warehouse
Report this ad
Javatpoint Services