Professional Documents
Culture Documents
PPT7 - MANIPULATORS in C++
PPT7 - MANIPULATORS in C++
PPT7 - MANIPULATORS in C++
Manipulators
in C++
Prepared & Presented By
Mrs.B.Meena Preethi
Assistant Professor
Department of SS
Sri Krishna Arts and Science
College
ODD 2020-21
Learners Support Publications www.lsp4you.com
TOPICS TO BE COVERED
Manipulators in C++
What is a Manipulator ?
Manipulators are operators used in C++
for formatting output.
The data is manipulated by the
programmer's choice of display.
Manipulators are functions specifically
designed to be used in conjunction with
the insertion (<<) and extraction (>>)
operators on stream objects, for example:
cout<< endl;
Learners Support Publications www.lsp4you.com
Manipulators are functions specifically designed to be used in conjunction with the insertion (<<) and extraction (>>) operators on stream objects, for examp
Manipulators in C++
Manipulator Declaration in
endl iostream.h
setw iomanip.h
setprecision iomanip.h
setf iomanip.h
setbase iomanip.h
Endl manipulator
endl manipulator is used to Terminate a
line and flushes the buffer.
std::endl sends a newline character '\n'
and flushes the output buffer.
'\n' sends the newline character, but does
not flush the output buffer.
Endl manipulator
Example
#include <iostream.h>
int main()
{
cout<<"USING '\\n' ...\n";
cout<<"Line 1 \nLine 2 \nLine 3 \n"; cout<<"USING end
..."<< endl;
cout<< "Line 1" << endl << "Line 2" << endl << "Line 3" <<
endl; return 0;
}
Syntax
setw([number_of_characters]);
setfill([character]);
Output
Syntax
setw([number_of_characters]);
setfill([character]);
Syntax:
setprecision([number_of_digits]);
Syntax:
setprecision([number_of_digits]);
Example:
cout<<setprecision(5)<<1234.537;
// output will be : 1234.5
setbase:
changes base of integer output
load <iomanip>
Accepts an integer argument (10, 8, or 16)
cout << setbase(16) << n;
parameterized stream manipulator - takes an argument
a) endl
b) setw
c) Setfill
.4. _____ change base of which integers are interpreted from
the stream
a) setwidth
b) setprecision
c) setbase
d) All the above
Learners Support Publications www.lsp4you.com
MCQ
5. __________character is used in output insertion
operations to fill spaces when results have to be padded to
the field width.
a) endl
b) setw
c) Setfill
d) setbase
.