string str = "123";
std::cout << (boost::format("%05d") % str).c_str();
だったかな。(うろ覚え)

std::cout << boost::str(boost::format("%05d") % str);
とか。(うろ憶え)