View Full Version : What exactly is endl????

06-14-2007, 11:22 AM
Hi all,

I am trying to find out exactly what endl actually is.

The C++ documentation that I have found just nonchalantly throws it in as "Oh, this is what you use for a newline character", but it doesn't explain what it actually IS.

I have tried cout << typeid(endl).name() << endl; but, maddeningly, the compiler doesn't like that! So it would seem that I can't find anything that tells me what it is and I can't write a program to find out what it is!!!

:mad: :mad: :mad:

For the moment I am using my own function macro to define endl, which explicitly checks the operating system and substitutes the appropriate const char array (either "\n" or "\r\n"). (not ideal because it's partially compiler-dependent, but at least I know what my endl actually is!).

I am asking this question because iostream's endl is causing problems for an overloaded version of the << inserter for a class that I have written which is derived from the stringstream class - if I use my version of endl then the problem goes away.



06-14-2007, 06:24 PM
If I recall endl should actually be part of iomanip so you should have at the top of your program

#include <iostream>
#include <iomanip>

06-14-2007, 07:45 PM
Apart from appending a new line endl also flushes the buffer. It's a pointer to a function IIRC.

06-15-2007, 12:20 PM
Ok thanks marek, that's probably why it screws up my overloaded operator!

06-15-2007, 08:54 PM
You could create your own manipulator that adds the right newline and works like endl and the other manipulators.