LAB MANUAL - Docx 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

LAB MANUAL

LAB # 3
Header file:-
These are those files that store predefined functions. It
contains definitions of functions that you can include or import
using a preprocessor directive #include. This preprocessor
directive tells the compiler that the header file needs to be
processed prior to the compilation.

Iostream :-
Iostream provides us with various functions to handle the
input and output stream in c++. This iostream header file
contains various functions, including cin, cout, cin, and many
more. With the help of this, we can read the input, print them, and
also trace the error, if any.

Cin :-
The "c" in C++ cin refers to "character" and "in" means
"input". Thus, cin means "character input". The C++ cin object
belongs to the istream class. (>>)

Example :-
Cout :-
It is defined in iostream header file. It is used to display the
output to the standard output device i.e. monitor. It is
associated with the standard C output stream stdout. The data
needed to be displayed on the screen is inserted in the standard
output stream (cout) using the insertion operator (<<).

Example :-

Cin.get :-
The cin. get() C++ function is used to access the character
array and it also includes the white space character inside
the output. Expanding the cin. get() function, the c stands for
"character" and the in stands for "input" and the get() here means
that the function will also take the whitespace along with the input.
Example :-

Cin.ignore :-
The cin.ignore() function is that which is used to ignore or clear one or
more characters from the input buffer.

Example :-

Cin.putback :-
So the function of cin. putback() is clear from its name itself. It put
the values back into the buffer and move the pointer
backwards.

Cin.peek :-
The 'peek' function on input streams (in your case cin ) retrieves
the next character from the stream without actually
consuming it. That means that you can "preview" the next
character in the input, and on the next call to any consuming
operation (overloaded operator >> or cin.

EXAMPLE :-

OUTPUT :-
Manuplator :-
Manipulators are special functions that can be included in the I/O
statement to alter the format parameters of a stream. We should
add <iomanip> header file before using its functions.
 SETPRECISION :-
The setprecision() method of iomanip library in C++ is used to
set the ios library floating point precision based on the
precision specified as the parameter to this method.
Syntax: setprecision (n)
 FIXED :-
The fixed() method of stream manipulators in C++ is used to set
the floatfield format flag for the specified str stream. This flag
sets the floatfield to fixed. It means that the floating-point values
will be written in fixed point notations.
 SHOWPOINT :-
The showpoint function is a manipulator that sets the showpoint
flag, which tells an output stream to write a decimal point for
floating-point output, even if the point is unnecessary (only zeros
appear after the decimal point). Specifically, the function calls
stream. setf(ios_base::showpoint) and returns stream .
 SETW :-
Setw function is a C++ manipulator which stands for set width.
Show the value of expression of specific column if the number of
column exceed the number of column required output of the
expression is right justified unuse column to the left filled with the
spaces if the number of column less then the number required the
output expand to the number required .

Example :-

You might also like