Boost logo

Boost Users :

Subject: Re: [Boost-users] RES: How do I print a standard pair?
From: Krzysztof Żelechowski (giecrilj_at_[hidden])
Date: 2011-09-26 03:51:54


Matheus Peschke de Azevedo wrote:

> Krzysztof,
>
> According to the C++ standard, the ostream output (cout and wcout) will
> only handle built-in types (e.g., int, char, double, etc).

Not true, vide ::std:: complex.

> It's up to the
> developer implement how all other types will print to the output. See full
> rationale and details in Stroustrup, Bjarne TCPPPL 3rd Edition - 21.2.2
> Output of Built In Types.
>
> In short, you'll have to define a global operator<< for type std::pair<T,
> U>:
>
> template<typename CharType, typename T, typename U>
> std::basic_ostream<CharType>& operator<< (std::basic_ostream<CharType>& o,
> std::pair<T, U> mypair)
> {
> return o << "This is my way of printing a pair: first: " <<
> mypair.first << " and second: " << mypair.second;
> }

This is strictly forbidden by the standard AFAIK.

Chris


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net