//http://stackoverflow.com/questions/6010864/copying-stringstream/6010930#6010930
 
#include <iostream>
#include <sstream>
using namespace std;
 
int main() 
{
        stringstream ss;
        streambuf *coutbuf = cout.rdbuf();
        cout.rdbuf(ss.rdbuf());
        cout << "this goes to the stringstream" << endl;
        string s = ss.str();
        cout.rdbuf(coutbuf);
        cout << "after cour.rdbuf : " << s;
        return 0;
}
