I've been looking and I'm a bit lost about how to change the target of ostream so that I could write to other buffers than the console.

The streams work on a streambuf object. The streambuf is an abstract base class that provides a buffer interface for use by the stream objects (like ostream and istream). Two derived class are provided by the standard, the filebuf and stringbuf classes (where, obviously, the filebuf reads/writes to a file and the stringbuf reads/writes to a string (or character array)).

To associate a stream with a given streambuf object, you can use the rdbuf() function.

If you want to actually create your own streambuf derived class, then I don't really know how to do that, it is probably pretty hard. But usually, either the filebuf or stringbuf should be sufficient for a given application, for instance, most OSes implement things like COM-ports, internet sockets, or console/terminal IO as files (things like look like files anyways, pseudo-files if you want).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.