同じ文字列 (ログ メッセージなど) を複数のストリームに送信する必要があります。
次の解決策のうち、最も効率的なのはどれですか?
ストリームごとに同じ文字列を再構築し、それをストリーム自体に送信します。
outstr1 << "abc" << 123 << 1.23 << "def" << endl; outstr2 << "abc" << 123 << 1.23 << "def" << endl; outstr3 << "abc" << 123 << 1.23 << "def" << endl;
文字列の演算子で一度文字列を構築し、それをすべてのストリームに送信します。
std::string str = "abc" + std::to_string(123) + std::to_string(1.23) + "def"; outstr1 << str; outstr2 << str; outstr3 << str;
ストリームで文字列を 1 回作成し、それをすべてのストリームに送信します。
std::stringstream sstm; sstm << "abc" << 123 << 1.23 << "def" << endl; std::string str = sstm.str(); outstr1 << str; outstr2 << str; outstr3 << str;
これらの出力ストリームの一部またはすべてが RAM ディスク上にある可能性があります。
同じことを行う他の方法はありますか?