SlideShare una empresa de Scribd logo
1 de 15
Manipulators in C++
Manipulators
● Manipulators are functions specifically designed to be used in
conjunction with the insertion (<<) and extraction (>>)
operators on stream objects.
● Manipulators are used to change formatting parameters on
streams and to insert or extract certain special characters.
● Manipulators are classified into two,
1. Manipulators without arguments
2. Manipulators with Arguments
Manipulators without arguments
● endl: It is defined in ostream.
It is used to enter a new line and after entering a new line it flushes.
● ws: It is defined in istream and is used to ignore the whitespaces in the string sequence.
● Ends: It inserts a null character into the output stream. It typically works with std::ostrstream.
● flush: It flushes the output stream i.e. it forces all the output written on the screen or in the file.
Manipulators without arguments
int main()
{
istringstream str(" Programmer");
string line;
// Ignore all the whitespace in string
getline(str >> std::ws, line);
cout << line << endl;
cout << "only a test" << flush;
cout << "na";
cout << "b" << ends;
cout << "c" << endl;
return 0;
}
Manipulators with arguments
1. setw (val): It is used to sets the field width in output operations.
2. setfill (c): It is used to fill the character ‘c’ on output stream.
3. setprecision (val): It sets val as the new value for the precision of
floating-point values.
4. setbase(val): It is used to set the numeric base value for numeric
values.
5. setiosflags(flag): It is used to sets the format flags specified by
parameter mask.
6. resetiosflags(m): It is used to resets the format flags specified by
parameter mask.
Manipulators with arguments
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
double f =3.14159;
cout <<setw(10)<< 77 <<endl;
cout << setprecision(3) << f << 'n';
cout << setfill ('x') << setw (10)<< 77 << endl;
cout << setbase(16)<< 110 << endl;
}
Basic format flags
Independent flags (switch on)
boolalpha Alphanumerical bool values.
showbase Show numerical base prefixes.
showpoint Show decimal point.
showpos Show positive signs.
skipws Skip whitespaces.
unitbuf Flush buffer after insertions.
uppercase Generate upper case letters.
Independent flags (switch off)
noboolalpha Do alphanumerical bool values.
noshowbase Do not show numerical base prefixes.
noshowpoint Do not show decimal point.
noshowpos Do not show positive signs.
noskipws Do not skip whitespaces.
nounitbuf Do not force flushes after insertions.
nouppercase Do not generate upper case letters.
Basic format flags :
*boolalpha & noboolalpha
bool b = true;
cout << boolalpha << b << 'n';
cout << noboolalpha << b << 'n';
*showbase & noshowbase
int n = 20;
cout << hex << showbase << n << 'n';
cout << hex << noshowbase << n << 'n';
Output:
true
1
Output:
0x14
14
Basic format flags :
*setpoint & nosetpoint
double a = 30,b = 3.141543;
cout.precision (5);
cout << showpoint << a << 't' << b<<endl;
cout << noshowpoint << a << 't' << b;
*showpos & noshowpos
int p = 1;
int n = -1;
cout << showpos << p << 't' << n << 'n';
cout << noshowpos << p << 't' << n << 'n';
Output:
30.000 3.1415
30 3.1415
Output:
+1 -1
1 -1
*skipws & noskipws
char a, b, c;
istringstream iss (" 123");
iss >> skipws >> a >> b >> c;
cout << a << b << c << 'n';
iss.seekg(0);
iss >> noskipws >> a >> b >> c;
cout << a << b << c << 'n';
*uppercase & nouppercase
cout << hex;
cout << uppercase << 77 << 'n';
cout << nouppercase << 77 << 'n';
Output:
123
1
Output:
4D
4d
Numerical base format flags ("basefield" flags)
dec Use decimal base
hex Use hexadecimal base
oct Use octal base
Floating point format flags ("floatfield" flags)
fixed Use fixed floating point notation
scientific Use scientific floating point notation
Numerical base format flags ("basefield" flags)
*dec & hex & oct
int n = 70;
cout << dec << n << 'n';
cout << hex << n << 'n';
cout << oct << n << 'n';
*fixed & scientific
double a = 3.1415926534;
cout.precision(5);
cout << a <<"n";
cout << fixed << a <<"n" ;
cout << scientific << a <<"n";
Output:
70
46
106
Output:
3.1416
3.14159
3.1415e+000
Adjustment format flags ("adjustfileld "flags)
internal Sets field by inserting characters at an internal position.
left Adjust output to the left.
right Adjust output to the right.
Adjustment format flags ("adjustfileld "flags)
*internal & left & right
int n = -5;
cout.width(6); cout << internal << n << 'n';
cout.width(6); cout << left << n << 'n';
cout.width(6); cout << right << n << 'n';
Output:
- 5
-5
-5

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Function overloading
Function overloadingFunction overloading
Function overloading
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Python list
Python listPython list
Python list
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
String functions in C
String functions in CString functions in C
String functions in C
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Structure & union
Structure & unionStructure & union
Structure & union
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Array and string
Array and stringArray and string
Array and string
 
C programming - String
C programming - StringC programming - String
C programming - String
 

Similar a Manipulators in c++

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 overloadingkinan keshkeh
 
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 JobyGrejoJoby1
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it outrajatryadav22
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequencesInput and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequencesssuserf86fba
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingMd. Ashikur Rahman
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersJen Yee Hong
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptxNelyJay
 
Formatted Console I/O Operations in C++
Formatted Console I/O Operations in C++Formatted Console I/O Operations in C++
Formatted Console I/O Operations in C++sujathavvv
 

Similar a Manipulators in c++ (20)

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++ 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
 
C++InputOutput.pptx
C++InputOutput.pptxC++InputOutput.pptx
C++InputOutput.pptx
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Managing console
Managing consoleManaging console
Managing console
 
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequencesInput and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
 
input
inputinput
input
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 
strings
stringsstrings
strings
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmers
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
Formatted Console I/O Operations in C++
Formatted Console I/O Operations in C++Formatted Console I/O Operations in C++
Formatted Console I/O Operations in C++
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
 

Más de Ashok Raj

How c++ stored in ram
How c++ stored in ramHow c++ stored in ram
How c++ stored in ramAshok Raj
 
Command line arguments
Command line argumentsCommand line arguments
Command line argumentsAshok Raj
 
High Performance Computer
High Performance ComputerHigh Performance Computer
High Performance ComputerAshok Raj
 
Super computers
Super computersSuper computers
Super computersAshok Raj
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler languageAshok Raj
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigmsAshok Raj
 
Printers and its types
Printers and its typesPrinters and its types
Printers and its typesAshok Raj
 
Microprocessor
MicroprocessorMicroprocessor
MicroprocessorAshok Raj
 
Mother board
Mother boardMother board
Mother boardAshok Raj
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systemsAshok Raj
 
FULL stack -> MEAN stack
FULL stack -> MEAN stackFULL stack -> MEAN stack
FULL stack -> MEAN stackAshok Raj
 

Más de Ashok Raj (11)

How c++ stored in ram
How c++ stored in ramHow c++ stored in ram
How c++ stored in ram
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
High Performance Computer
High Performance ComputerHigh Performance Computer
High Performance Computer
 
Super computers
Super computersSuper computers
Super computers
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigms
 
Printers and its types
Printers and its typesPrinters and its types
Printers and its types
 
Microprocessor
MicroprocessorMicroprocessor
Microprocessor
 
Mother board
Mother boardMother board
Mother board
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systems
 
FULL stack -> MEAN stack
FULL stack -> MEAN stackFULL stack -> MEAN stack
FULL stack -> MEAN stack
 

Último

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Último (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Manipulators in c++

  • 2. Manipulators ● Manipulators are functions specifically designed to be used in conjunction with the insertion (<<) and extraction (>>) operators on stream objects. ● Manipulators are used to change formatting parameters on streams and to insert or extract certain special characters. ● Manipulators are classified into two, 1. Manipulators without arguments 2. Manipulators with Arguments
  • 3. Manipulators without arguments ● endl: It is defined in ostream. It is used to enter a new line and after entering a new line it flushes. ● ws: It is defined in istream and is used to ignore the whitespaces in the string sequence. ● Ends: It inserts a null character into the output stream. It typically works with std::ostrstream. ● flush: It flushes the output stream i.e. it forces all the output written on the screen or in the file.
  • 4. Manipulators without arguments int main() { istringstream str(" Programmer"); string line; // Ignore all the whitespace in string getline(str >> std::ws, line); cout << line << endl; cout << "only a test" << flush; cout << "na"; cout << "b" << ends; cout << "c" << endl; return 0; }
  • 5. Manipulators with arguments 1. setw (val): It is used to sets the field width in output operations. 2. setfill (c): It is used to fill the character ‘c’ on output stream. 3. setprecision (val): It sets val as the new value for the precision of floating-point values. 4. setbase(val): It is used to set the numeric base value for numeric values. 5. setiosflags(flag): It is used to sets the format flags specified by parameter mask. 6. resetiosflags(m): It is used to resets the format flags specified by parameter mask.
  • 6. Manipulators with arguments #include <iomanip> #include <iostream> using namespace std; int main() { double f =3.14159; cout <<setw(10)<< 77 <<endl; cout << setprecision(3) << f << 'n'; cout << setfill ('x') << setw (10)<< 77 << endl; cout << setbase(16)<< 110 << endl; }
  • 7. Basic format flags Independent flags (switch on) boolalpha Alphanumerical bool values. showbase Show numerical base prefixes. showpoint Show decimal point. showpos Show positive signs. skipws Skip whitespaces. unitbuf Flush buffer after insertions. uppercase Generate upper case letters.
  • 8. Independent flags (switch off) noboolalpha Do alphanumerical bool values. noshowbase Do not show numerical base prefixes. noshowpoint Do not show decimal point. noshowpos Do not show positive signs. noskipws Do not skip whitespaces. nounitbuf Do not force flushes after insertions. nouppercase Do not generate upper case letters.
  • 9. Basic format flags : *boolalpha & noboolalpha bool b = true; cout << boolalpha << b << 'n'; cout << noboolalpha << b << 'n'; *showbase & noshowbase int n = 20; cout << hex << showbase << n << 'n'; cout << hex << noshowbase << n << 'n'; Output: true 1 Output: 0x14 14
  • 10. Basic format flags : *setpoint & nosetpoint double a = 30,b = 3.141543; cout.precision (5); cout << showpoint << a << 't' << b<<endl; cout << noshowpoint << a << 't' << b; *showpos & noshowpos int p = 1; int n = -1; cout << showpos << p << 't' << n << 'n'; cout << noshowpos << p << 't' << n << 'n'; Output: 30.000 3.1415 30 3.1415 Output: +1 -1 1 -1
  • 11. *skipws & noskipws char a, b, c; istringstream iss (" 123"); iss >> skipws >> a >> b >> c; cout << a << b << c << 'n'; iss.seekg(0); iss >> noskipws >> a >> b >> c; cout << a << b << c << 'n'; *uppercase & nouppercase cout << hex; cout << uppercase << 77 << 'n'; cout << nouppercase << 77 << 'n'; Output: 123 1 Output: 4D 4d
  • 12. Numerical base format flags ("basefield" flags) dec Use decimal base hex Use hexadecimal base oct Use octal base Floating point format flags ("floatfield" flags) fixed Use fixed floating point notation scientific Use scientific floating point notation
  • 13. Numerical base format flags ("basefield" flags) *dec & hex & oct int n = 70; cout << dec << n << 'n'; cout << hex << n << 'n'; cout << oct << n << 'n'; *fixed & scientific double a = 3.1415926534; cout.precision(5); cout << a <<"n"; cout << fixed << a <<"n" ; cout << scientific << a <<"n"; Output: 70 46 106 Output: 3.1416 3.14159 3.1415e+000
  • 14. Adjustment format flags ("adjustfileld "flags) internal Sets field by inserting characters at an internal position. left Adjust output to the left. right Adjust output to the right.
  • 15. Adjustment format flags ("adjustfileld "flags) *internal & left & right int n = -5; cout.width(6); cout << internal << n << 'n'; cout.width(6); cout << left << n << 'n'; cout.width(6); cout << right << n << 'n'; Output: - 5 -5 -5