Boost logo

Boost Users :

Subject: [Boost-users] [format] Reuse of the format object
From: Maxime van Noppen (maxime_at_[hidden])
Date: 2011-04-11 06:27:30


Hi,

I've got a question about the reuse of the boost::format object. Given
this minimal testcase:

-----------------------------------------------------------
#include <iostream>
#include <boost/format.hpp>

int main()
{
  boost::format fmt("%|=12| %|=12| %|=12|\n");

  // 1
  std::cout
    << boost::str(fmt % "a" % "b" % "c")
    << boost::str(fmt % 1 % 2 % 3);

  // 2
  std::cout
    << fmt % "a" % "b" % "c"
    << fmt % 1 % 2 % 3;
}
-----------------------------------------------------------

Why is 1 working while 2 produces the runtime exception:

> terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::io::too_many_args> >'
> what(): boost::too_many_args: format-string referred to less arguments than were passed

?

I didn't find an explanation about this in the doc & the example about
the reuse of format objects here:

http://www.boost.org/doc/libs/1_46_1/libs/format/example/sample_advanced.cpp

Using boost 1.46.0 and g++ 4.5.2.

Thanks,

-- 
Maxime

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net