Using Manipulators to Format I/O : cout « Development « C++ Tutorial






/*
Manipulator                   Purpose                             Input/Output

boolalpha                     Turns on boolapha flag.             Input/Output

dec                           Turns on dec flag.                  Input/Output

endl                          Output a newline character and flush the stream.   Output

ends                          Output a null.                      Output

fixed                         Turns on fixed flag.                Output

flush                         Flush a stream.                     Output

hex                           Turns on hex flag.                  Input/Output

internal                      Turns on internal flag.             Output

left                          Turns on left flag.                 Output

nobooalpha                    Turns off boolalpha flag.           Input/Output

noshowbase                    Turns off showbase flag.            Output

noshowpoint                   Turns off showpoint flag.           Output

noshowpos                     Turns off showpos flag.             Output

noskipws                      Turns off skipws flag.              Input

nounitbuf                     Turns off unitbuf flag.             Output

nouppercase                   Turns off uppercase flag.           Output

oct                           Turns on oct flag.                  Input/Output

resetiosflags (fmtflags f)    Turn off the flags specified in f.  Input/Output

right                         Turns on right flag.                Output

scientific                    Turns on scientific flag.           Output

setbase(int base)             Set the number base to base.        Input/Output

setfill(int ch)               Set the fill character to ch.       Output

setiosflags(fmtflags f)       Turn on the flags specified in f.   Input/output

setprecision (int p)          Set the number of digits of precision. Output

setw(int w)                   Set the field width to w.           Output

showbase                      Turns on showbase flag.             Output

showpoint                     Turns on showpoint flag.            Output

showpos                       Turns on showpos flag.              Output

skipws                        Turns on skipws flag.               Input

unitbuf                       Turns on unitbuf flag.              Output

uppercase                     Turns on uppercase flag.            Output

ws                            Skip leading white space.           Input
*/


#include <iostream>
#include <iomanip>
using namespace std;
   
int main()
{
  cout << hex << 100 << endl;
   
  cout << setfill('?') << setw(10) << 2343.0;
   
  return 0;
}








5.2.cout
5.2.1.parameterless manipulators that operate on output streams
5.2.2.To use a parameterized manipulator, you must include . It defines the following manipulators:
5.2.3.Using Manipulators to Format I/O
5.2.4.Use std::cout to output message to console
5.2.5.Use std::cout to output various data
5.2.6.Printing a line of text with multiple statements
5.2.7.Use std::endl to output a new line sign
5.2.8.cout: unsetf
5.2.9.Printing multiple lines of text with a single statement: use the \n
5.2.10.Output a pointer
5.2.11.Use function in cout statement
5.2.12.cout: setf()
5.2.13.cout: flags() and unsetf()
5.2.14.cout: width()
5.2.15.cout: precision()
5.2.16.cout: fill()
5.2.17.Using write().
5.2.18.An I/O manipulator: cout << setprecision(2)
5.2.19.An I/O manipulator: cout << setw(20)
5.2.20.use the setiosflags( ) manipulator to directly set the various format flags related to a stream.
5.2.21.cout: setiosflags()
5.2.22.Skip leading whitespace.
5.2.23.Scientific mode; don't show plus sign anymore
5.2.24.Fixed-point mode, show a '+' for positive nums, show 3 digits to the right of the decimal
5.2.25.setiosflags(ios::showpos); and setiosflags(ios::showbase);
5.2.26.ios::showpos | ios::showbase | ios::oct | ios::right
5.2.27.Set cout to output hex
5.2.28.Show default condition of format flags
5.2.29.cout.setf(ios::showpoint | ios::showpos, ios::showpoint);
5.2.30.Set ios::showpoint, ios::showpos for double pointer number
5.2.31.OR together two or more flags
5.2.32.unset flag one by one
5.2.33.cout boolalpha: cause bool values to display as true or false
5.2.34.Demonstrating the flags member function
5.2.35.Using showpoint to control the printing of trailing zeros anddecimal points for doubles
5.2.36.Demonstrating left justification and right justification
5.2.37.Printing an integer with internal spacing and plus sign
5.2.38.Using stream-manipulator showbase to show number base
5.2.39.Stream-manipulator uppercase.
5.2.40.Demonstrating stream-manipulators boolalpha and noboolalpha.
5.2.41.Controlling precision of floating-point values.
5.2.42.Check cout flags