Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2004-04-21 16:54:10


John Torjo wrote:
>> Dear boosters,
>>
>> When needing to dump a lot of data into a string, we usually use
>> boost::format. However, there have been lots of times when I needed a
>> simple and lightweight replacement.
>>
>> I've used one for quite a while (see attachement).
>> Basic usage:
>> str_stream() << "str" << s << "int " << i; // automatic conversion to
>> string.
>> Example:
>> std::string msg = str_stream() << "There have been " << users << "
>> users
>> logged on so far";
>>
>> Also, attached an example.
>> Any interest in something like this in boost?

What is wrong with:

std::ostringstream oss;

oss << "There have been " << users << "users logged on so far";
std::string msg(oss.str());

This can probably even be:

std::string msg((std::ostringstream() << "There have been " << users <<
"users logged on so far").str());

I have to admit that I don't understand any of the reasons for using
printf... functions or boost::format instead of the C++ string streams. The
latter seem much more natural and easier to me, and are further supported by
boost::lexical_cast to make trivial conversions to and from strings even
easier.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk