>From: "Vladimir Prus" <[EMAIL PROTECTED]> > after having to output std::vector to stream again and again using custom > solution, I started to wonder why we don't have a solution in boost. > Does it makes sense to include operators<< for vectors, sets, etc? > > I was thinking about > > <boost/io/vector.hpp> > <boost/io/set.hpp> > > and so on. There are basically two approaches: > > 1. Operators use fixed format: bracked list with commas between values for > vector, for example. > 2. Manipulators are provided to set brackets and separators. > > I had implemented the second approach some time ago, but it turned out that > was overkill. So, 1) looks better now. > > Thoughts?
You can do this quite well using the standard library and stream iterator adapters. This may do both of your approaches above. For example: --- Start --- #include <iostream> #include <string> #include <vector> #include <algorithm> #include <iterator> int main() { std::vector<std::string> list; list.push_back("A"); list.push_back("B"); list.push_back("C"); typedef std::ostream_iterator<std::string> Out; std::cout << "Print vector\n"; std::copy(list.begin(),list.end(),Out(std::cout,"\n")); } --- End --- Output: Print vector A B C Regards, Terje _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost