2013/1/16 Chris Stankevitz
On Tue, Jan 15, 2013 at 5:49 PM, Steve Lorimer
wrote: Think about what happens if you feed multiple elements via operator% and then call .str() - you get a std::string back - it has to store everything you've fed in internally so that you can access the formatted string later via .str()
Steve,
Thank you. I never used boost::format::str, but I agree that its presence indicates that operator% must alter an internal state.
Question 1: Is there an efficient way to do the following (and by "more efficient" I mean fewer format constructors and string parsing):
void WriteLog(float x, float y, float z, const Employee& e) { std::cout << "Values: " << boost::format("%0.3") % x << e << boost::format("%0.3") % y << boost::format("%0.3") % z; }
Hi, I'm no expert here, but I'd try this: boost::format const fmt("%0.3" ); cout << boost::format(fmt) % x << e << boost::format(fmt) %y ... HTH, Kris