メソッドpubsetbufを使用して、文字列をコピーせずに文字列ストリームオブジェクトの文字列バッファを変更しようとしていますが、機能していません。http://www.cplusplus.com/reference/iostream/streambuf/pubsetbuf/のドキュメントに従っています。これが私のサンプルコードです:
#include <iostream>
#include <sstream>
int main(int argc, char* argv[])
{
std::stringstream stream("You say goodbye");
char replace[] = {"And I say hello"};
std::cout << stream.str() << std::endl; // Checking original contents
stream.rdbuf()->pubsetbuf(replace, 16); // Should set contents here
std::cout << stream.str() << std::endl; // But don't :(
return 0;
}
そして、出力は次のとおりです。
You say goodbye
You say goodbye
stream.str(replace)を使用できることはわかっていますが、このメソッドは'replace'の値をコピーするため、コピーを作成したくありません。
私は何が欠けていますか?
更新:VS2010を使用しています