Manipulators In C++





Manipulators
Manipulators are operators used with the insertion operator << to modify or manipulate the way data is displayed. It just changes certain characteristics of the input and output.

The following are the manipulators used in c++:-

  • Endl

It is a manipulator that causes a line feed to be inserted into the stream. It I similar to ‘\n’ character.E.g. Cout<<”a=”<<a<<endl;

// Program to display a message on two new lines using the endl manipulator

#include<iostream.h>
#include<conio.h>
Void main ()
{
Cout<<”hello”<<endl;
Cout<<”many greetings”<<endl;
getch ();
}

  • Setw()

This Setw () stands for the set width. The Setw () manipulator is used to set the width of the word to be displayed on screen. The general form of Setw () is:-

Setw (int w)

Where, the integer inside the bracket indicates the total field width.

E.g. // demonstrate Setw () manipulator

#include<iostream.h>
#include<iomanip.h>      // for Setw ()
#include<conio.h>
Void main ()
{
Cout<<Setw (10) <<”name”<<Setw (10) <<”marks”<<endl;
Cout<<Setw (10) <<”ram”<<Setw (10) <<”95”<<endl;
Cout<<Setw (10) <<”hari”<<Setw (10) <<”85”<<endl;
getch ();
}



Related posts:

  1. Introduction to Set Theory The concept of modern mathematics is started with set....
  2. Relation between sets. If , in any condition two or more sets appears...
  3. Set Theory formulas Set Theory is a branch of mathematics which deals with...
  4. Type Conversion In C++ Type Conversion In C++ This process of converting one predefined...
  5. Introduction To Functions. A Function from set A to set B is a...