On Monday, 3. April 2006 17:18, Jerry Feldman wrote:
I've seen a number of documents and code that prefers to use the newline
character ("\n" or '\n') rather than std::endl
In the general case, the issue is that endl forces a buffer flush where
'\n' does not, and therefore using the newline is more efficient. However,
using endl is more portable. Either way works fine on Linux. Comments... --
I think the choice is purely if you would like the buffer flush or not. The is no portability issue with '\n':
In the ISO standard section 27.6.2.7 std::endl is defined as
namespace std {
template basic_ostream& endl(basic_ostream& os);
}
1 Effects: Calls os.put(os.widen('\n') ), then os.flush().
2 Returns: os
As you can see the line is terminated by outputing the char '\n'. In this case it is first widened. In the case
of os << '\n'; it will also be widened as specified in 27.6.2.5.4
Put simply in formatted output streams the char '\n' represents a line termination whatever the underling OS.
Michael
--
___________________________________
Michael Stevens Systems Engineering
34128 Kassel, Germany
Phone/Fax: +49 561 5218038
Navigation Systems, Estimation and
Bayesian Filtering
http://bayesclasses.sf.net
___________________________________