Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost format] Not getting expected errors
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2013-07-13 17:22:39


> I’m doing: > > string myString = (boost::format(“%i”) % 1.1).str(); > > I would expect that to either throw an error (preferred) or cast to an > int and then format. I’m seeing a similar issue with %x and %o etc. Any > thoughts? According to the Boost.Format documentation [1], the effect of the %i format specifier is to output its argument in a decimal base, not to force it to be an integer. There appears to be no way to specify in the format string that an argument should be coerced to be an integer, or that an exception should be thrown if it's not. The idea behind a strongly-typed formatting library is that the information about the types of the arguments is contained in, well, the types of the arguments, not in the format string. The format string is used to specify additional information that is not encoded in the type of the argument, like the base. Regards, Nate [1] http://www.boost.org/doc/libs/1_54_0/libs/format/doc/format.html#printf_directives


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