次のコードを試します。
ostringstream oss;
streambuf *psbuf, *backup;
backup = oss.rdbuf();
psbuf = cout.rdbuf();
oss.rdbuf(psbuf);
oss << things << endl;
oss.rdbuf(backup);
しかし、残念ながら私はこのエラーが発生します:
error: too many arguments to function call, expected 0, have 1
oss.rdbuf(backup);
ただし、rdbuf には 2 つのオーバーロードがあります。
get (1) basic_streambuf<char_type,traits_type>* rdbuf() const;
set (2) basic_streambuf<char_type,traits_type>* rdbuf (basic_streambuf<char_type,traits_type>* sb);
はい、私はそれが言うことを知っていますbasic_streambuf
が、実際には単なる typedeftypedef basic_streambuf<char> streambuf;
であるため、動作するはずです。なぜ機能しないのですか?