On Sunday 11 January 2009, Christoph Duelli wrote:
I recently had the need to produce from a vector<uint> a string representation (like for IPs) like "23.1.4.742.234.0".
You could also use Karma (part of the Spirit 2 library) for that job. See the included example. HTH, Chris #include <boost/assign/std/vector.hpp> // for 'operator+=()' #include <boost/spirit/include/karma.hpp> #include <cassert> #include <cstdlib> #include <vector> using namespace boost::assign; // bring 'operator+=()' into scope using namespace boost::spirit; using namespace boost::spirit::ascii; int main() { std::vector<int> v; v += 23, 1, 4, 742, 234, 0; std::string generated; bool success = karma::generate(std::back_inserter(generated), int_ % ".", // format description v // data ); assert(success && "23.1.4.742.234.0" == generated); return EXIT_SUCCESS; }