que tal si rediriges el buffer a un
stringstream?
Código C++:
Ver original#include <iostream>
#include <fstream>
#include <sstream>
int main()
{
std::stringstream buffer;
std::streambuf * old = std::cout.rdbuf(buffer.rdbuf());
std::cout << "hola mundo" << std::endl;
std::cout << "hola mundo" << std::endl;
std::cout << "hola mundo" << std::endl;
std::string text = buffer.str();
std::ofstream file;
file.open ("test.txt");
file << text;
file.close();
}