cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : ios_base : flags
- -
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::flags public member function
fmtflags flags ( ) const;
fmtflags flags ( fmtflags fmtfl );

Get/set format flags

The first syntax returns the current set of format flags set for the stream.
The second syntax sets a new set of format flags for the stream, returning its former value.

The format flags of a stream affect the way data is interpreted in certain input functions and how it is written by certain output functions. See ios_base::fmtflags for the possible values of this function's argument.

The second syntax of this function sets the value for all the format flags of the stream, overwritting the existing values and clearing any flag not explicitly set in the argument. To modify just a single format flag, the member functions setf and unsetf are generally preferred.

Parameters

fmtfl
Format flags to be used by the stream. It is a value of type ios_base::fmtflags.

Return Value

The format flags of the stream before the call.

Example

// modify flags
#include <iostream>
using namespace std;

int main () {
  cout.flags ( ios::right | ios::hex | ios::showbase );
  cout.width (10);
  cout << 100;
  return 0;
}

This simple example sets some format flags for cout that affect the latter insertion operation by printing the value in hexadecimal base format (0x64) padded right as in a field ten spaces long:

      0x64

See also

ios_base::setf Set specific format flags (public member function)
ios_base::unsetf Clear specific format flags (public member function)
ios_base::fmtflags Type for stream format flags (public member type)
setiosflags Set format flags (manipulator function)

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