Unfortunately, you can't. In concept of C++ std library you must use streams (like as stdout, stdin and etc). This method was perfectly described by Alexandrescu in his book "Modern C++...". But personally I like to use old good method as Format. And I have invented my own function. May be it will be useful for you
string_smart Format(cstr szText,...)
{
cstr szPtr=szText;
size_t lLen;
//Calculating Average length
for (lLen=0;*szPtr; ++szPtr,(*szPtr=='%') ?lLen+=10:lLen++);
string\_cstr strRes(++lLen);
va\_list marker;
va\_start( marker, szText);
while (\_vsnprintf(strRes.buffer(),strRes.buffer\_size()-1,szText,marker) <0 )
strRes.reserve(strRes.buffer\_size()\*2);
//\_ASSERTE( \_CrtCheckMemory( ));
strRes.buffer()\[strRes.buffer\_size()-1\]='\\0'; //Don't remove this line!
strRes.recalc\_len();
va\_end( marker );
return strRes;
}
This function works with my class string_smart, but it is not hard to remake it for std::string