equivalent of sprintf in C++

Hi
My requirement is to convert the following to C++

char buffer[90];
sprintf(buffer,"%s %-50s %6s %-6d %s\n",a.substr(0,5),a.substr(10,20))

Since the buffer is of varying length, i cannot hardcode the value as 90.
i would like to convert the buffer to string object so that it can receive any number of bytes. So ... i will be converting buffer to string object.

So i need some formatting in C++. Is there any thing similar to sprintf?

Regards
Dhana

Use sstream.

#include <sstream>
using namespace std;

int main()
{
stringstream ss;
ss<<"Formatted date example (H:M:S):"<<hour<<":"<<min<<":"<<sec<<endl;
cout<<ss.str().c_str();
return 0;
}