Write a formatted string to a stream