• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » C++ » Oops » Escape Sequences and Manipulators in c++
Next →
← Prev

Escape Sequences and Manipulators in c++

By Dinesh Thakur

Escape Sequences

Commonly used escape sequences are \n, \t and \a. The escape sequences are enclosed in single quotes. \n is a new line character and helps in transferring control to the next line. If more than one line is to be skipped, \n is repeated as many times as the number of lines to be skipped. \n can also be combined with any other message string to be displayed. \t is used for giving tab and \a is used for giving a beep.

Example

Illustrates the use of \t and \a escape sequences.</p

//newtab.cpp
#include 
void main() {
  int i,j,k,m;
  cout<<"Enter the value of i, j, k, m \n";
  cin>>i>>j>>k>>m;
  cout<<endl;
  cout<<'\a '<<i<<'\t'<<j<<'\t'<<k<<'\t'<<m<<'\n';
}

Input and Output:

Enter the value of i, j, k, m

1234

1          2          3         4

Manipulators

These are used for manipulating the display of output in the desired format. Manipulators are used with insertion operator <<. These are included in the <iomanip.h> header file. Hence this header file should be included in the program.

flush Manipulator

This manipulator is used for flushing the buffer.

endl Manipulator

The endl manipulator is used for flushing the buffer and for inserting a new line simultaneously.

setw Manipulator

This manipulator facilitates the user to specify the field width explicitly in order to have better display of output. The syntax is

setw(field width);

The field width must be of int type.

Example

Illustrates the use of the manipulators flush, endl and setw().

//setw.cpp
#include 
#include 
void main() {
  char entryno[10];
  char name[10];
  int fee;
  cout<<"Enter the entry number "<<endl;
  cin>>entryno;
  cout<<"Enter the name "<<flush<<'\n';
  cin>>name;
  cout<<"Enter the fees "<<endl;
  cin>>fee;
  cout<<endl;
  cout<<setw(18)<<"Entry number"<<setw(12)<<entryno<<endl;
  cout<<setw(10)<<"Name "<<setw(20)<<name<<endl;
  cout<<setw(10)<<"Fees "<<setw(20)<<fee<<endl;
} 

Input and Output:

Enter the entry number

MAC0797

Enter the name

Sanjay

Enter the fees

1200

Entry number  MAC0797

Name               Sanjay

Fees                 1200

Following is a program to find the minimum and maximum limits for char, short, int, long int, float, double and long double type of data.

Example

The Program finds the limit for char, short, int, long int, float, double and long double type of data. The keywords for finding the limits for float, double and long double (written in capital letters in the program) are found in float.h header file. The keywords for finding the limits for other types are found in limits.h header file.

#include 
#include 
#include 
void main() {
   cout<<"minimum char value is "<<CHAR_MIN<<"\n" ;
   cout<<"maximum char value is "<<CHAR_MAX<<"\n" ;
   cout<<"minimum short value is "<<SHRT_MIN<<"\n" ;
   cout<<"maximum short value is "<<SHRT_MAX<<"\n" ;
   cout<<"minimum int value is "<<INT_MIN<<"\n\n" ;
   cout<<"maximum int value is "<<INT_MAX<<"\n'" ,
   cout<<"minimum long int value is "<<LONG_MIN<<"\n\n";
   cout<<"maximum long int value is "<<LONG_MAX<<"\n";
   cout<<"min. no. of significant digits in float is "<<FL_T_DIG<<"\n";
   cout<<"max. no of bits for mantissa is "<<FLT_MANT_DIG<<"\n";
   cout<<" min. exponent value in float is "<<FLT_MIN_10_EXP<<"\n";
   cout<<"max. exponent value in float is "<<FLT_MAX_10_EXP<<"\n\n";
   cout<<"min. no. of significant \n";
   cout<<"digits in double is "<<DBL_DIG<<"\n\n";
   cout<<"max. no. of bits for mantissa is "<<DBL_MANT_DIG<<"\n";
   cout<<"min. exponent value in double is "<<DBL_MIN_10_EXP<<"\n\n";
   cout<<"max. exponent value in double is "<<DBL_MAX_10_EXP<<"\n";
   cout<<"min. no. of significant\n";
   cout<<"digits in long double "<<LDBL_DIG<<"\n\n";
   cout<<"max. no. of bits for mantissa is "<<LDBL_MANT_DIG<<"\n";
   cout<<"min. exponent value in long double is n<<LDBL_MIN_10_Exp<<n\n";
   cout<<"max. exponent value in long double is n<<LDBL_MAX_10_EXP<<"\n\n";
} 

Output:

minimum char value is -128

maximum char value is 127

minimum short value is -32768

maximum short value is 32767

minimum int value is -2147483648

maximum int value is 2147483647

minimum long int value is -2147483648

maximum long int value is . 2147483647

min. no. of significant digits in float is 6

max. no. of bits for mantissa is 24

min. exponent value in float is -37

max. exponent value in float is 38

min. no. of significant

digits in double is 15

max. no. of bits for mantissa is 53

min. exponent value in double is -307

max. exponent value in double is 308

min. no. of significant

digits in long double 15

max. no. of bits for mantissa is 53

min. exponent value in long double is -307

max. exponent value in long double is 308

You’ll also like:

  1. Escape Sequences in C
  2. Java Escape Sequences Examples
  3. Manipulators in C++
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

C++ Tutorials

C++ Tutorials

  • C++ - Data Types
  • C++ - Operators Types
  • C++ - CPP Program Structure
  • C++ - Conditional Statements
  • C++ - Loop
  • C++ - do-While Loop
  • C++ - Control Statements
  • C++ - Tokens
  • C++ - Jump Statements
  • C++ - Expressions
  • C++ - Constants
  • C++ - Character Set
  • C++ - Iteration Statements
  • C++ - I/O Statements
  • C++ - String
  • C++ - Manipulators

C++ Operator

  • C++ - Input/Output Operator
  • C++ - Operator Overloading

C++ Functions

  • C++ - Functions
  • C++ - Member Functions
  • C++ - Returning Object from Function
  • C++ - Call by Value Vs Reference
  • C++ - Friend Function
  • C++ - Virtual Function
  • C++ - Inline Function
  • C++ - Static Data Members
  • C++ - Static Member Functions

C++ Array & Pointer

  • C++ - Array
  • C++ - Array of Objects
  • C++ - Arrays as Class Members
  • C++ - Vector
  • C++ - Pointer
  • C++ - 'this' Pointer

C++ Classes & Objects

  • C++ - Class
  • C++ - Program Structure With Classes
  • C++ - OOP’s
  • C++ - Objects as Function Arguments
  • C++ - Procedure Vs OOL
  • C++ - Object Vs Class
  • C++ - Creating Objects
  • C++ - Constructors
  • C++ - Copy Constructor
  • C++ - Constructor Overloading
  • C++ - Destructor
  • C++ - Polymorphism
  • C++ - Virtual Base Class
  • C++ - Encapsulation

C++ Inheritance

  • C++ - Inheritance
  • C++ - Multiple Inheritance
  • C++ - Hybrid Inheritance
  • C++ - Abstraction
  • C++ - Overloading

C++ Exception Handling

  • C++ - Exception Handling
  • C++ - Templates
  • C++ - Standard Template Library

C++ Data Structure

  • C++ - Link List

C++ Programs

  • C++ Program for Electricity Bill
  • C++ Program for Multiply Matrices
  • C++ Program for Arithmetic Operators
  • C++ Program For Matrices
  • C++ Program for Constructor
  • C++ Program Verify Number
  • C++ Program Array Of Structure
  • C++ Program to find Average Marks
  • C++ Program Add And Subtract Matrices
  • C++ Program Menu Driven
  • C++ Program To Simple Interest
  • C++ Program To Find Average
  • C++ program exit()
  • C++ Program Using Array Of Objects
  • C++ Program Private Member Function
  • C++ Program To Reverse A String
  • C++ Program to Operator Overloading

Other Links

  • C++ - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2023. All Rights Reserved.