Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
filebuf
fstream
ifstream
ios
iostream
ios_base
istream
istringstream
ofstream
ostream
ostringstream
streambuf
stringbuf
stringstream
objects:
cerr
cin
clog
cout
types:
fpos
streamoff
streampos
streamsize
manipulators
boolalpha
dec
endl
ends
fixed
flush
hex
internal
left
noboolalpha
noshowbase
noshowpoint
noshowpos
noskipws
nounitbuf
nouppercase
oct
resetiosflags
right
scientific
setbase
setfill
setiosflags
setprecision
setw
showbase
showpoint
showpos
skipws
unitbuf
uppercase
ws


right

manipulator function
<ios>
ios_base& right ( ios_base& str );

Adjust output to the right

Sets the adjustfield format flag for the str stream to right.

When adjustfield is set to right, the output is padded to the field width by inserting fill characters at the beginning, effectively adjusting the field to the right.

The adjustfield format flag can take any of the following values (each with its own manipulator):

flag valueeffect when set
internalthe output is padded to the field width by inserting fill characters at a specified internal point.
leftthe output is padded to the field width appending fill characters at the end.
rightthe output is padded to the field width by inserting fill characters at the beginning.

The adjustfield flag is set to right in standard streams on initialization with the default locale.

Parameters

str
Stream object where to apply.
Because this function is a manipulator, it is designed to be used alone with no arguments in conjunction with the insertion (<<) and extraction (>>) operations on streams (see example below).

Return Value

A reference to the stream object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// modify adjustfield using manipulators
#include <iostream>
using namespace std;
int main () {
  int n;
  n=-77;
  cout.width(6); cout << right << n << endl;
  cout.width(6); cout << internal << n << endl;
  cout.width(6); cout << left << n << endl;
  return 0;
}


The execution of this example displays something similar to:
   -77
-   77
-77

See also