cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : manipulators : right
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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_base& right ( ios_base& str );
<ios>

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

// 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

internal Adjust field by inserting characters at an internal position (manipulator function)
left Adjust output to the left (manipulator function)
ios_base::flags Get/set format flags (public member function)
ios_base::setf Set specific format flags (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us