cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : ios_base : width
- -
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
ios_base
· ios_base::ios_base
· ios_base::~ios_base
member classes:
· ios_base::failure
· ios_base::Init
member functions:
· ios_base::flags
· ios_base::getloc
· ios_base::imbue
· ios_base::iword
· ios_base::precision
· ios_base::pword
· ios_base::register_call...
· ios_base::setf
· ios_base::sync_with_stdio
· ios_base::unsetf
· ios_base::width
· ios_base::xalloc
member types:
· ios_base::event
· ios_base::event_callback
· ios_base::fmtflags
· ios_base::iostate
· ios_base::openmode
· ios_base::seekdir

-

ios_base::width public member function
streamsize width ( ) const;
streamsize width ( streamsize wide );

Get/set field width

The first syntax returns the current value of the field width.
The second syntax sets a new field width for the object.

The field width determines the minimum number of characters to be written in some output representations. If the standard width of the representation is shorter than the field width, the representation is padded with fill characters at a point determined by the format flag adjustfield (left, right or internal).

The fill character can be retrieved or changed by calling the member function ios::fill.

The format flag adjustfield can be modified by calling the member functions flags or setf, by inserting one of the following manipulators: left, right and internal, or by inserting the parameterized manipulator setiosflags.

The field width can also be modified using the parameterized manipulator setw.

Parameters

wide
New value for the stream's field width. This is an integral value of type streamsize.

Return Value

The value of the field width before the call.

Example

// field width
#include <iostream>
using namespace std;

int main () {
  cout << 100 << endl;
  cout.width(10);
  cout << 100 << endl;
  cout.fill('x');
  cout.width(15);
  cout << left << 100 << endl;
  return 0;
}

See also

setw Set field width (manipulator function)
ios_base::flags Get/set format flags (public member function)
ios_base::setf Set specific format flags (public member function)
ios::fill Get/set the fill character (public member function)

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