C++语言程序设计

下面是iostream.h中ostream类的部分定义，可以告诉我们如何使用运算符重载。

| 程序12-3

/*
* Formatted insertion operations
*/
// insert the character
ostream _FAR & _Cdecl operator<< ( signed char);
ostream _FAR & _Cdecl operator<< (unsigned char);

//for the following, insert character representation of numeric value
ostream _FAR & _Cdecl operator<< (short);
ostream _FAR & _Cdecl operator<< (unsigned short);
ostream _FAR & _Cdecl operator<< (int);
ostream _FAR & _Cdecl operator<< (unsigned int);
ostream _FAR & _Cdecl operator<< (long);
ostream _FAR & _Cdecl operator<< (unsigned long);
ostream _FAR & _Cdecl operator<< (float);
ostream _FAR & _Cdecl operator<< (double);
ostream _FAR & _Cdecl operator<< (long double);

// insert the null-terminated string
ostream _FAR & _Cdecl operator<< (const signed char _FAR *);
ostream _FAR & _Cdecl operator<< (const unsigned char _FAR *);

// insert character representation of the value of the pointer
ostream _FAR & _Cdecl operator<< (void _FAR *);

// extract from streambuf, insert into this ostream
ostream _FAR & _Cdecl operator<< (streambuf _FAR *);

// manipulators
ostream _FAR & _Cdecl operator<< (ostream _FAR & (_Cdecl *_f)(ostream _FAR &));
ostream _FAR & _Cdecl operator<< (ios _FAR & (_Cdecl *_f)(ios _FAR &));