<iomanip>


get_money · get_time · put_money · put_time · quoted


resetiosflags · setbase · setfill · setiosflags · setprecision · setw


Include the iostreams standard header <iomanip> to define several manipulators that each take a single argument. Each of these manipulators returns an unspecified type, called T1 through T6 here, that overloads both basic_istream<Elem, Tr>::operator>> and basic_ostream<Elem, Tr>::operator<<. Thus, you can write extractors and inserters such as:

cin >> setbase(8);
cout << setbase(8);
namespace std {
T1 resetiosflags(ios_base::fmtflags mask);
T2 setiosflags(ios_base::fmtflags mask);
T3 setbase(int base);
template<class Elem>
    T4 setfill(Elem ch);
T5 setprecision(streamsize prec);
T6 setw(streamsize wide);

template<class Money>
    T7 get_money(Money& amount, bool intl); [added with C++11]
template<class Money>
    T8 put_money(const Money& amount, bool intl); [added with C++11]
template<class Elem>
    T9 get_time(struct tm *tptr, const Elem *fmt); [added with C++11]
template<class Elem>
    T10 put_time(struct tm *tptr, const Elem *fmt); [added with C++11]

template<class Elem>
    T11 quoted(const Elem *ptr,
        Elem delim = Elem('"'), Elem escape = Elem('\\')); [added with C++14]
template<class Elem, class Tr, class Alloc>
    T11 quoted(const basic_string<Elem, Tr, Alloc>& str,
        Elem delim = Elem('"'), Elem escape = Elem('\\')); [added with C++14]
template<class Elem, class Tr, class Alloc>
    T12 quoted(basic_string<Elem, Tr, Alloc>& str,
        Elem delim = Elem('"'), Elem escape = Elem('\\')); [added with C++14]
}  // namespace std

get_money

template<class Money>
    T7 get_money(Money& amount, bool intl); [added with C++11]

The manipulator returns an object that, when extracted from the stream str, behaves as a formatted input function that calls the member function get for the locale facet money_get associated with str, using intl to indicate international format. If successful, the call stores in amount the extracted monetary value. The manipulator then returns str.

Money must be of type long double or an instantiation of basic_string with the same element and traits parameters as str.

get_time

template<class Elem>
    T9 get_time(struct tm *tptr, const Elem *fmt); [added with C++11]

The manipulator returns an object that, when extracted from the stream str, behaves as a formatted input function that calls the member function get for the locale facet time_get associated with str, using tptr to indicate the time structure and fmt to indicate the beginning of a NUL-terminated format string. If successful, the call stores in the time structure the values associated with any extracted time fields. The manipulator then returns str.

put_money

template<class Money>
    T8 put_money(const Money& amount, bool intl); [added with C++11]

The manipulator returns an object that, when inserted into the stream str, behaves as a formatted output function that calls the member function put for the locale facet money_put associated with str. If successful, the call inserts amount suitably formatted, using intl to indicate international format and str.fill(), as the fill element. The manipulator then returns str.

Money must be of type long double or an instantiation of basic_string with the same element and traits parameters as str.

put_time

template<class Elem>
    T10 put_time(struct tm *tptr, const Elem *fmt); [added with C++11]

The manipulator returns an object that, when inserted into the stream str, behaves as a formatted output function that calls the member function put for the locale facet time_put associated with str, using tptr to indicate the time structure and fmt to indicate the beginning of a NUL-terminated format string. If successful, the call inserts literal text from the format string and converted values from the time structure. The manipulator then returns str.

quoted

template<class Elem>
    T11 quoted(const Elem *ptr,
        Elem delim = Elem('"'), Elem escape = Elem('\\')); [added with C++14]
template<class Elem, class Tr, class Alloc>
    T11 quoted(const basic_string<Elem, Tr, Alloc>& str,
        Elem delim = Elem('"'), Elem escape = Elem('\\')); [added with C++14]
template<class Elem, class Tr, class Alloc>
    T12 quoted(basic_string<Elem, Tr, Alloc>& str,
        Elem delim = Elem('"'), Elem escape = Elem('\\')); [added with C++14]

The quoted manipulators simplify the transparent insertion and extraction of character sequences that may contain whitespace or other elements that might terminate an extracted field.

The first manipulator returns an object that, when inserted into the stream str, behaves as a formatted output function. It inserts the elements of the NTBS beginning at ptr, suitably escaped, preceded and followed by an instance of delim. Each element of the NTBS that matches delim is preceded by an instance of escape. The manipulator then returns str.

The second manipulator behaves the same as the first, except that the inserted elements are the str.size() elements beginning at str.c_str().

The third manipulator returns an object that, when extracted from the stream str, extracts and discards a leading instance of delim, extracts and appends to str (which is initially cleared) suitably escaped elements, then extracts and discards a trailing instance of delim. Each extracted element that matches escape is replaced by the following element (which may match delim or escape). The manipulator then returns str.

resetiosflags

T1 resetiosflags(ios_base::fmtflags mask);

The manipulator returns an object that, when extracted from or inserted into the stream str, calls str.setf(ios_base:: fmtflags(), mask), then returns str.

setbase

T3 setbase(int base);

The manipulator returns an object that, when extracted from or inserted into the stream str, calls str.setf(mask, ios_base::basefield), then returns str. Here, mask is determined as follows:

setfill

template<class Elem>
    T4 setfill(Elem ch);

The template manipulator returns an object that, when extracted from or inserted into the stream str, calls str.fill(ch), then returns str. The type Elem must be the same as the element type for the stream str.

setiosflags

T2 setiosflags(ios_base::fmtflags mask);

The manipulator returns an object that, when extracted from or inserted into the stream str, calls str.setf(mask), then returns str.

setprecision

T5 setprecision(streamsize prec);

The manipulator returns an object that, when extracted from or inserted into the stream str, calls str.precision(prec), then returns str.

setw

T6 setw(streamsize wide);

The manipulator returns an object that, when extracted from or inserted into the stream str, calls str.width(wide), then returns str.


See also the Table of Contents and the Index.

Copyright (c) by P.J. Plauger. All rights reserved.