c++string-formattingboost-format

boost::format() output operator


I need to write the class which will accept boost::format() through the operator like cout does:

cout << boost::format("some string; some param = %d\n") % someValue;

Which type of operator's parameter must be? So that the class will be declared like this:

class Output
{
    Output& operator<<(... format);
}
int main()
{
    Output output;
    output << boost::format("...");
}

Thanks.


Solution

  • boost::format is the type you want. It has a str() member to get a std::string.