Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts

    What exactly is endl????

    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!!!



    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.

    TIA,

    Mike.

  • #2
    New Coder
    Join Date
    May 2007
    Location
    SF, CA
    Posts
    55
    Thanks
    0
    Thanked 4 Times in 4 Posts
    If I recall endl should actually be part of iomanip so you should have at the top of your program

    Code:
    #include <iostream>
    #include <iomanip>

  • #3
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Apart from appending a new line endl also flushes the buffer. It's a pointer to a function IIRC.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #4
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Ok thanks marek, that's probably why it screws up my overloaded operator!

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You could create your own manipulator that adds the right newline and works like endl and the other manipulators.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •