SlideShare a Scribd company logo
By
A.Sujatha M.Sc.,M.Phil.,PGDCA.,
Department of Mathematics
 Formatted console input/output functions are used
for performing input/output operations at console
and the resulting data is formatted and
transformed.
Some of the most important formatted console
input/output functions are –
Functions Description
width()
Using this function, we can specify the
width of a value to be displayed in the
output at the console.
precision()
Using this function, we can specify the
number of digits(num_of_digits) to the
right of decimal, to be printed in the
output.
fill()
Using this function, we can fill the
unused white spaces in a value(to be
printed at the console), with a character
of our choice.
setf()
Using this function, we can set the
flags, which allow us to display a value
in a particular format.
unsetf() Using this function, we can clear the
flags specified.
Using the width() function
Using this function, we can specify the width of a
value to be displayed in the output at the console. Let's
see the syntax of width() function -
cout.width(w);
Where, w is the value to be displayed in the output at
the console.
Example of width() function -
//The width() function defines width of the next value to
be displayed in the output at the console.
#include<iostream>
using namespace std;
int main()
{
char ch = 'a';
//Adjusting the width of the next value to
displayed to 5 columns.
cout.width(5);
cout<<ch <<"n";
int i = 1;
//width of the next value to be displayed in the
output will not be adjusted to 5 columns.
cout<<i;
}
Filling and padding:
Fill:
The member function can be used to fill the unusual position of
the field by any desired character.It can be invoked by object cout.
Syntax:
Cout.fill(‘ch’)
Where ch represents the character which is used for filling the used
position.
Ex:
Cout.fill(‘*’);
Cout.width(‘/0’);
Cout<<5250<<endl;
Output:
x x x x x x 5 2 5 0
#include<iostream.h>
#include<conio.h>
Using name space std;
Void main( )
{
Cout.full(‘<’);
Cout.precision(3);
For(int n=1;n<=6;n++)
{
Cout.width(5);
Cout<<n;
Cout.width(10);
Cout<<1.0/float(n)<<endl;
If(n==3)
Cout.fill(‘>’);
}
Cout<<”/n padding changed/n”;
Cout.fill(‘#’); //fill( )reset
Cout.width(15);
Cout<<12.345678<<endl;
}
Output:
<<<<1<<<<<<<<<1
<<<<2<<<<<<<0.5
<<<<3<<<<<0.333
>>>>4>>>>>>0.25
>>>>5>>>>>>>0.2
>>>>6>>>>>>0.167
Padding changed
#########12.345678
Setf( )
It is a member function of ios class.It is used to set
flags. It can be invoked by using the object cout.
Syntax:
Cout.setf(arg1,arg2);
Where arg1 is one of the formatting flags define in the class
ios arg2 is nothing but a bitfield. Hence formatting flag says
the format action for her output.
ios::skipus 5.skip white space on input
ios::unitpuf 6.flush all stream after all insertion
ios::stdio 7.flush stdout and stderr after insertion
Note:
The flags set by setup( ) remain effective until they are
reset.
A format flag can be reset any no. of time in a programme.
Managing output with manipulators:
The header file iomanip provides a set of
functions called manipulators. They are used to
manipulate the output formats.
Manipulators and their meanings:
Manipulators Meaning equivalent
Setw(int w) Set the field width of w Width ( )
Set precision (int d) Set the floating point
precision to d
Precision( )
Set fill(int c) Set the fill character to c Fill ( )
Setiosflags (long f) Set the format flag f Setf( )
endl Insert new line and flush
stream
“/n”
Formatting with maniplutors
#include<iostream.h>
#include<conio.h>
Using namespace std;
Void main( )
{
Cout.setf(ios::show point);
Cout<<setw(5)<<”n”<<setw(15)<<”Inverse of n”<<setw(15)<<”sum of terms/n/n” ;
Double term, sum=0;
For(int n=1;n<=10;n++)
{
Term=1.0/float(n);
Sum=sum+term;
Cout<<setw(5)<<n<<setw(14)<<set
procision(4)<<setiosflags(ios::scientific)<<term<<sum<<endl;
}
}
Designing out own Manipulators
We can design our own manipulators for some special characters.
Syntax:
For creating a manipulator without any argument is
O stream & manipulator(ostream & output)
{
-------
-------
-------
Return(output);
}
Ex:
Ostream & unit(ostream&output)
{
Output<<”inches”;
Return<<output;
}
The above function defines a manipulator called unit that
displays inches. This statement cout<<36<<unit; will produce
the output 36 inches
#include<iostream>
#include<iomanip.h>
Using namespace std;
//user defined manipulators
Ostream & currency(ostream &output)
{
Output<<”Rs”;
Return output;
}
Ostream &form (ostream & output)
{
Output.setf(cos:: show pos);
Output.setf(cos::show point);
Output.fill(*);
Output.precision(2);
Output<<setio flags(cos::fixed);
<<setw(10);
Return output;
}
Void main( )
{
Cout<<currency<<term<<78645;
}

More Related Content

What's hot

Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
File system structure
File system structureFile system structure
File system structure
sangrampatil81
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
cprogrammings
 
directory structure and file system mounting
directory structure and file system mountingdirectory structure and file system mounting
directory structure and file system mounting
rajshreemuthiah
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
Haresh Jaiswal
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
P M Patil
 
This pointer
This pointerThis pointer
This pointer
Kamal Acharya
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
Muhammad Waqas
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
Avinash Varma Kalidindi
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
Dashani Rajapaksha
 
[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)
Muhammad Hammad Waseem
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
shekhar1991
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
Array in c
Array in cArray in c
Array in c
Ravi Gelani
 
Address resolution protocol (ARP)
Address resolution protocol (ARP)Address resolution protocol (ARP)
Address resolution protocol (ARP)
NetProtocol Xpert
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
Tech_MX
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
Abid Kohistani
 

What's hot (20)

Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
File system structure
File system structureFile system structure
File system structure
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 
directory structure and file system mounting
directory structure and file system mountingdirectory structure and file system mounting
directory structure and file system mounting
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
This pointer
This pointerThis pointer
This pointer
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Array in c
Array in cArray in c
Array in c
 
Address resolution protocol (ARP)
Address resolution protocol (ARP)Address resolution protocol (ARP)
Address resolution protocol (ARP)
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
 

Similar to Formatted Console I/O Operations in C++

Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
Pranali Chaudhari
 
C++InputOutput.pptx
C++InputOutput.pptxC++InputOutput.pptx
C++InputOutput.pptx
ansariparveen06
 
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
kinan keshkeh
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
yamew16788
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
KamranAli649587
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
SURBHI SAROHA
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
deepak kumbhar
 
Complete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdfComplete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdf
access2future1
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
Mohammad Shaker
 
Quiz 9
Quiz 9Quiz 9
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
gourav kottawar
 
Oops presentation
Oops presentationOops presentation
Oops presentation
sushamaGavarskar1
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
vandna123
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
aksachdevahosymills
 
Function C++
Function C++ Function C++
Function C++
Shahzad Afridi
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
NelyJay
 
Constants and Unformatted Input Output Functions.pptx
Constants and Unformatted Input Output Functions.pptxConstants and Unformatted Input Output Functions.pptx
Constants and Unformatted Input Output Functions.pptx
DrJasmineBeulahG
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
 

Similar to Formatted Console I/O Operations in C++ (20)

Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
C++InputOutput.pptx
C++InputOutput.pptxC++InputOutput.pptx
C++InputOutput.pptx
 
Managing console
Managing consoleManaging console
Managing console
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
Complete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdfComplete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdf
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
 
Function C++
Function C++ Function C++
Function C++
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
Constants and Unformatted Input Output Functions.pptx
Constants and Unformatted Input Output Functions.pptxConstants and Unformatted Input Output Functions.pptx
Constants and Unformatted Input Output Functions.pptx
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
 

More from sujathavvv

Vector calculus
Vector calculusVector calculus
Vector calculus
sujathavvv
 
Complex analysis
Complex analysisComplex analysis
Complex analysis
sujathavvv
 
Z transforms
Z transformsZ transforms
Z transforms
sujathavvv
 
Programming in c++ ppt
Programming in c++ pptProgramming in c++ ppt
Programming in c++ ppt
sujathavvv
 
Vector calculus
Vector calculusVector calculus
Vector calculus
sujathavvv
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
sujathavvv
 
Complex analysis
Complex analysisComplex analysis
Complex analysis
sujathavvv
 
Trigonometry & vector calculus
Trigonometry & vector calculusTrigonometry & vector calculus
Trigonometry & vector calculus
sujathavvv
 
Complex analysis
Complex analysisComplex analysis
Complex analysis
sujathavvv
 
Differential equation and Laplace Transform
Differential equation and Laplace TransformDifferential equation and Laplace Transform
Differential equation and Laplace Transform
sujathavvv
 
Differential equation and Laplace transform
Differential equation and Laplace transformDifferential equation and Laplace transform
Differential equation and Laplace transform
sujathavvv
 
Sequences and Series
Sequences and SeriesSequences and Series
Sequences and Series
sujathavvv
 
Sequences and Series
Sequences and SeriesSequences and Series
Sequences and Series
sujathavvv
 
Programming in C
Programming in CProgramming in C
Programming in C
sujathavvv
 
Programming in c
Programming in cProgramming in c
Programming in c
sujathavvv
 

More from sujathavvv (15)

Vector calculus
Vector calculusVector calculus
Vector calculus
 
Complex analysis
Complex analysisComplex analysis
Complex analysis
 
Z transforms
Z transformsZ transforms
Z transforms
 
Programming in c++ ppt
Programming in c++ pptProgramming in c++ ppt
Programming in c++ ppt
 
Vector calculus
Vector calculusVector calculus
Vector calculus
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
 
Complex analysis
Complex analysisComplex analysis
Complex analysis
 
Trigonometry & vector calculus
Trigonometry & vector calculusTrigonometry & vector calculus
Trigonometry & vector calculus
 
Complex analysis
Complex analysisComplex analysis
Complex analysis
 
Differential equation and Laplace Transform
Differential equation and Laplace TransformDifferential equation and Laplace Transform
Differential equation and Laplace Transform
 
Differential equation and Laplace transform
Differential equation and Laplace transformDifferential equation and Laplace transform
Differential equation and Laplace transform
 
Sequences and Series
Sequences and SeriesSequences and Series
Sequences and Series
 
Sequences and Series
Sequences and SeriesSequences and Series
Sequences and Series
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Programming in c
Programming in cProgramming in c
Programming in c
 

Recently uploaded

South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 

Recently uploaded (20)

South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 

Formatted Console I/O Operations in C++

  • 2.  Formatted console input/output functions are used for performing input/output operations at console and the resulting data is formatted and transformed. Some of the most important formatted console input/output functions are –
  • 3. Functions Description width() Using this function, we can specify the width of a value to be displayed in the output at the console. precision() Using this function, we can specify the number of digits(num_of_digits) to the right of decimal, to be printed in the output. fill() Using this function, we can fill the unused white spaces in a value(to be printed at the console), with a character of our choice. setf() Using this function, we can set the flags, which allow us to display a value in a particular format. unsetf() Using this function, we can clear the flags specified.
  • 4. Using the width() function Using this function, we can specify the width of a value to be displayed in the output at the console. Let's see the syntax of width() function - cout.width(w); Where, w is the value to be displayed in the output at the console. Example of width() function - //The width() function defines width of the next value to be displayed in the output at the console.
  • 5. #include<iostream> using namespace std; int main() { char ch = 'a'; //Adjusting the width of the next value to displayed to 5 columns. cout.width(5); cout<<ch <<"n"; int i = 1; //width of the next value to be displayed in the output will not be adjusted to 5 columns. cout<<i; }
  • 6. Filling and padding: Fill: The member function can be used to fill the unusual position of the field by any desired character.It can be invoked by object cout. Syntax: Cout.fill(‘ch’) Where ch represents the character which is used for filling the used position. Ex: Cout.fill(‘*’); Cout.width(‘/0’); Cout<<5250<<endl; Output: x x x x x x 5 2 5 0
  • 7. #include<iostream.h> #include<conio.h> Using name space std; Void main( ) { Cout.full(‘<’); Cout.precision(3); For(int n=1;n<=6;n++) { Cout.width(5); Cout<<n; Cout.width(10); Cout<<1.0/float(n)<<endl; If(n==3) Cout.fill(‘>’); } Cout<<”/n padding changed/n”; Cout.fill(‘#’); //fill( )reset Cout.width(15); Cout<<12.345678<<endl; }
  • 9. Setf( ) It is a member function of ios class.It is used to set flags. It can be invoked by using the object cout. Syntax: Cout.setf(arg1,arg2); Where arg1 is one of the formatting flags define in the class ios arg2 is nothing but a bitfield. Hence formatting flag says the format action for her output. ios::skipus 5.skip white space on input ios::unitpuf 6.flush all stream after all insertion ios::stdio 7.flush stdout and stderr after insertion Note: The flags set by setup( ) remain effective until they are reset. A format flag can be reset any no. of time in a programme.
  • 10. Managing output with manipulators: The header file iomanip provides a set of functions called manipulators. They are used to manipulate the output formats. Manipulators and their meanings:
  • 11. Manipulators Meaning equivalent Setw(int w) Set the field width of w Width ( ) Set precision (int d) Set the floating point precision to d Precision( ) Set fill(int c) Set the fill character to c Fill ( ) Setiosflags (long f) Set the format flag f Setf( ) endl Insert new line and flush stream “/n”
  • 12. Formatting with maniplutors #include<iostream.h> #include<conio.h> Using namespace std; Void main( ) { Cout.setf(ios::show point); Cout<<setw(5)<<”n”<<setw(15)<<”Inverse of n”<<setw(15)<<”sum of terms/n/n” ; Double term, sum=0; For(int n=1;n<=10;n++) { Term=1.0/float(n); Sum=sum+term; Cout<<setw(5)<<n<<setw(14)<<set procision(4)<<setiosflags(ios::scientific)<<term<<sum<<endl; } }
  • 13. Designing out own Manipulators We can design our own manipulators for some special characters. Syntax: For creating a manipulator without any argument is O stream & manipulator(ostream & output) { ------- ------- ------- Return(output); } Ex: Ostream & unit(ostream&output) { Output<<”inches”; Return<<output; }
  • 14. The above function defines a manipulator called unit that displays inches. This statement cout<<36<<unit; will produce the output 36 inches #include<iostream> #include<iomanip.h> Using namespace std; //user defined manipulators Ostream & currency(ostream &output) { Output<<”Rs”; Return output; } Ostream &form (ostream & output) { Output.setf(cos:: show pos);