I have to send the same string (e.g. a log message) to multiple streams.
Which of the following solutions is the most efficient?
Rebuild the same string for each stream and send it to the stream itself.
outstr1 << "abc" << 123 << 1.23 << "def" << endl; outstr2 << "abc" << 123 << 1.23 << "def" << endl; outstr3 << "abc" << 123 << 1.23 << "def" << endl;
Build the string once with string's operators, and send it to all the streams.
std::string str = "abc" + std::to_string(123) + std::to_string(1.23) + "def"; outstr1 << str; outstr2 << str; outstr3 << str;
Build the string once with a stream, and send it to all the streams:
std::stringstream sstm; sstm << "abc" << 123 << 1.23 << "def" << endl; std::string str = sstm.str(); outstr1 << str; outstr2 << str; outstr3 << str;
Some or all of these output streams could be on a RAM disk.
Any other ways to do the same thing?