Why is the argument of write restricted to a string/filename? If we use an output stream (std::ostream) we are more flexible. Then it is possible to give streams connected to 
- string streams (to save it more efficient to files for example),
- files,
- standard output.