stringstream-> rdbuf () -> pubsetbuf nie ustawia bufora
Próbuję zmodyfikować bufor łańcuchowy obiektu stringstream bez konieczności kopiowania łańcucha za pomocą metody pubsetbuf, ale nie działa. Śledzę dokumentację whttp://www.cplusplus.com/reference/iostream/streambuf/pubsetbuf/. Oto mój przykładowy kod:
#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;
}
A wyjście to:
You say goodbye
You say goodbye
Wiem, że mogę użyć stream.str (zastąpić), ale ta metoda kopiuje wartość 'replace' i nie chcę tworzyć kopii.
czego mi brakuje?
Aktualizacja: Używam VS2010