Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-09-06 05:31:03


Boris Kats wrote:
>I am using it for some time and hope that other will
>benefite from it.
>One file streamline.h will help user to stream out/in
>an arbitrary item of primitives or STL containers of
>them.
>It is very simple to use; just type like this:
>
>#include "streamline.h"
>using namespace hekate;
>.......
>typedef std::pair<std::string, std::vector<int> >
>element;
>element one,other;
>And stream it out as: streamline(cout,one);
>or stream it in as: streamline(cin,other); .
>
>User will find a lot of examples in the streamtest.cpp
>file
>at streamline.tar in "Files section".
>The streaming templates were tested with gcc version
>3.3.2, msvc7 and
>ibm89 c++ compiler.
>Boris Kats.

Hi Boris,

As Jonathan has pointed out, my library is aimed at solving this type of
problem. Your example would become:

#include <sstream>
#include <boost/outfmt/stl/vector.hpp>
#include <boost/outfmt/stl/pair.hpp>

int main()
{
   typedef std::pair< std::string, std::vector< int > > element;
   element one, other;

   one.first = "Meine \"Grosse\" Welt!";
   one.second.push_back( 3 );
   one.second.push_back( 6 );
   one.second.push_back( 9 );

   std::stringstream ss;
   ss << one;
   std::cout << "written: " << ss.str() << '\n';
   ss >> other;
   std::cout << "read: " << other << '\n';

   return( 0 );
}

Providing a much simpler syntax and stream integration. The output for this
is:
   written: ( "Meine \"Grosse\" Welt!", [ 3, 6, 9 ] )
   read: ( "Meine \"Grosse\" Welt!", [ 3, 6, 9 ] )

It is possible to control how the pair and vector types are rendered using a
custom formatter. Refer to the examples and documentation for more
information.

Regards,
Reece

_________________________________________________________________
Check out Election 2004 for up-to-date election news, plus voter tools and
more! http://special.msn.com/msn/election2004.armx


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk