OOPlecture8
OOPlecture8
► The input and output operation between the executing program and the
devices like keyboard and monitor are known as “console I/O operation”. The
input and output operation between the executing program and files are
known as “disk I/O operation”.
Classes for File stream operations :-
► 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.
► 1. ios:-ios stands for input output stream.
► 2. istream:-istream stands for input stream.This class is derived from the class
‘ios’.
► 3. ostream:-ostream stands for output stream.This class is derived from the
class ‘ios’.
► 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.
► 6. ifstream:-This class provides input operations. Inherits the functions get(),
getline(), read(), seekg() and tellg() functions from the istream.
► 7. ofstream:-This class provides output operations. Inherits the functions
put(), write(), seekp() and tellp() functions from the ostream.
► 8. fstream:-This class provides support for simultaneous input and output
operations.
► 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.
File Handling
Coding from lab
The C++ Standard Template Library (STL)
► A template is a simple yet very powerful tool in C++. The simple idea is to
pass the data type as a parameter so that we don’t need to write the same
code for different data types
► Two types of templates
► Function template
► Class template
Function template
► Containers: The STL provides a range of containers, such as vector, list, map,
set, and stack, which can be used to store and manipulate data.
► Algorithms: The STL provides a range of algorithms, such as sort, find, and
binary_search, which can be used to manipulate data stored in containers.
► Iterators: Iterators are objects that provide a way to traverse the elements of
a container. The STL provides a range of iterators, such as forward_iterator,
bidirectional_iterator, and random_access_iterator, that can be used with
different types of containers.
► Function Objects: Function objects, also known as functors, are objects that
can be used as function arguments to algorithms. They provide a way to pass
a function to an algorithm, allowing you to customize its behavior.
► Adapters: Adapters are components that modify the behavior of other
components in the STL. For example, the reverse_iterator adapter can be
used to reverse the order of elements in a container.
1. Algorithms
► The STL includes classes that overload the function call operator. Instances of
such classes are called function objects or functors. Functors allow the
working of the associated function to be customized with the help of
parameters to be passed.
4. Iterators
► As the name suggests, iterators are used for working on a sequence of values.
They are the major feature that allows generality in STL.