One should use endl() to write a newline to the stream instead of using \n.