1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
<HTML>
<HEAD>
<TITLE>PRINT_ELEMENTS()</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
<TABLE HEIGHT=40 WIDTH="100%">
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
<FONT face="Arial,Helvetica" size=+2><B>
PRINT_ELEMENTS()
</B></FONT>
</TD></TR></TABLE><BR>
<FONT face="Arial,Helvetica"><B>
The following code example is taken from the book<BR>
<A HREF="http://www.josuttis.com/libbook/" TARGET="_top">
The C++ Standard Library - A Tutorial and Reference</A><BR>
by Nicolai M. Josuttis, Addison-Wesley, 1999<BR>
<A HREF="http://www.josuttis.com/libbook/copyright.html">
© Copyright</A> Nicolai M. Josuttis 1999<BR>
</B></FONT>
<BR><BR>
<TT>
<SPAN class="Source">
#include <iostream><BR>
<BR>
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* print_elements()</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* - prints optional C-string optcstr followed by</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* - all elements of the collection coll</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* - separated by spaces</FONT></I><BR>
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
template <class T><BR>
inline void print_elements (const T& coll, const char* optcstr="")<BR>
{<BR>
typename T::const_iterator pos;<BR>
<BR>
std::cout << optcstr;<BR>
for (pos=coll.begin(); pos!=coll.end(); ++pos) {<BR>
std::cout << *pos << ' ';<BR>
}<BR>
std::cout << std::endl;<BR>
}<BR>
</SPAN>
</TT>
</BODY>
</HTML>
|