Boost logo

Boost Users :

Subject: [Boost-users] RES: How do I print a standard pair?
From: Matheus Peschke de Azevedo (mpeschke_at_[hidden])
Date: 2011-09-21 17:06:02


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

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;

Be advised that types T and U must be either built-in types or types with
defined operator<<.


-----Mensagem original-----
De: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] Em nome de Krzysztof
Enviada em: quarta-feira, 21 de setembro de 2011 11:59
Para: boost-users_at_[hidden]
Assunto: [Boost-users] How do I print a standard pair?

The expression (cout << make_pair (0, 1)) gives me an error. Does Boost
offer me a way to print a (rvalue) pair, as within an expression?

Boost-users mailing list

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at