You don't specify how you are measuring "efficiency" in this context. Here's one solution that is efficient in terms of code you must write and number of allocations:
#include <string>
#include <iostream>
using namespace std;
void format(const std::string& msg)
{
std::string banner(msg.length(), '=');
cout << banner << endl
<< msg << endl
<< banner << endl;
}
int main(int argc, char *argv[])
{
format("Some message");
format("Other message long one");
return 0;
}
I can imagine other alternatives that avoid allocating a temporary string for the banners, but those might come at an increased cost of the actual printing.