the ever elusive endl

DeRusto

Golden Member
May 31, 2002
1,249
0
86
hello, i was recently subjected to conflicting views on what exactly endl does.. on one side endl supposedly is just a replacement for "\n" << flush in the sense that it does the same thing...and the other side says endl does not do a flush..only something similar to a \n

i was just curious if anyone here knew what endl actually does:)

thanks
 

RedShirt

Golden Member
Aug 9, 2000
1,793
0
0
ENDL does something similar to a flush, but it is not as good as flush.

It is better than \n as far as flushage goes.
 

glugglug

Diamond Member
Jun 9, 2002
5,340
1
81
from the ostream template header in M$ visual studio:

template<class _E, class _Tr> inline
basic_ostream<_E, _Tr>&
__cdecl endl(basic_ostream<_E, _Tr>& _O)
{_O.put(_O.widen('\n'));
_O.flush();
return (_O); }
_CRTIMP2 inline basic_ostream<char, char_traits<char> >&
__cdecl endl(basic_ostream<char, char_traits<char> >& _O)
{_O.put('\n');
_O.flush();
return (_O); }
_CRTIMP2 inline basic_ostream<wchar_t, char_traits<wchar_t> >&
__cdecl endl(basic_ostream<wchar_t,
char_traits<wchar_t> >& _O)
{_O.put('\n');
_O.flush();
return (_O); }


So it looks like there is explicitly a flush in endl at least in M$ implementation. What's interesting is there isn't one in the implementation of ends.
 

DeRusto

Golden Member
May 31, 2002
1,249
0
86
hmm, that is VERY interesting:p

i never thought to look in the header file myself!! ah well.
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
endl implementation could be platform and library specific. On win32 using visual c++ libraries endl does a flush. Other platform might be defferent.
 

DeRusto

Golden Member
May 31, 2002
1,249
0
86
Originally posted by: Argo
endl implementation could be platform and library specific. On win32 using visual c++ libraries endl does a flush. Other platform might be defferent.

this is true:)
i wonder how the gcc compiler on linux handles endl
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
Originally posted by: DeRusto
Originally posted by: Argo
endl implementation could be platform and library specific. On win32 using visual c++ libraries endl does a flush. Other platform might be defferent.

this is true:)
i wonder how the gcc compiler on linux handles endl

Common sense would dictate that they're all the same. However, common sense doesn't always apply to software developers :)
 

DeRusto

Golden Member
May 31, 2002
1,249
0
86
Originally posted by: Argo
Originally posted by: DeRusto
Originally posted by: Argo
endl implementation could be platform and library specific. On win32 using visual c++ libraries endl does a flush. Other platform might be defferent.

this is true:)
i wonder how the gcc compiler on linux handles endl

Common sense would dictate that they're all the same. However, common sense doesn't always apply to software developers :)


haha, precisely;)