I have the following code, and I dont quite understand why the results happens to be like the one below:
#include <iostream>
#include <sstream>
using namespace std;
int main () {
std::stringstream s;
std::streambuf *backup;
backup = cout.rdbuf();
s << "Oh my god" << endl;
cout << "Before1" << endl;
cout << s.rdbuf();
cout << "After1" << endl;
cout << "Before2" << endl;
//s.seekg(0, std::ios_base::beg); // If that is in: After 2 is printed!
cout << s.rdbuf();
//cout.rdbuf(backup); // If that is in, also After 2 is printed!
cout << "After2" << endl;
}
Output:
Before1
Oh my god
After1
Before2
Where is the rest??¿ It only gets outputted when We uncomment the above lines... What happens internally? Does anybody know? =) Would be interesting...