Thread: Can you test this for me?

  1. #16
    Registered User
    Join Date
    Aug 2003
    the thing with endl is that it also flushes the ouput-buffer, making sure that anything in the output-buffer is printed/written/something else. To achieve the same with \n you would have do a << flush aswell.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  2. #17
    Been here, done that.
    Join Date
    May 2003
    Quote Originally Posted by swgh
    some excellent points, just a quickie

    Daved, if what you say is true then why was I taught at college in C++ to use endl and only use "\n" when the need was justified?
    Why are other instructors teaching
    void main()
    They don't know any better! I believe your instructor is correct (for the reason Shakti pointed out), but if he taught any of the above, any 'never'/'always' statement would be questionable IMAO.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  3. #18
    Registered User
    Join Date
    Jan 2005
    >> Daved, if what you say is true then why was I taught at college in C++ to use endl and only use "\n" when the need was justified?

    First, many, many things that are taught by instructors, books, tutorials and even forum posters are based on habit and experience rather than current best practice. Apparently, before C++ was standardized, you were allowed to use the endl when you included <iostream.h>, so most everybody did. Then when the standard was made, in what may have just been an oversight, they defined the language in such a way that you weren't guaranteed to get endl when you included <iostream>. But all the standard library writers continued to allow it (possibly because so much existing code relied on it).

    So all the people in the habit of using endl with iostream just continued to do so. I personally still use endl without including <ostream> because that was how I was taught as well. It is an extremely trivial issue because most (or all) compilers allow it.

    That said, the teaching and reference tools should be as correct as possible. So the wiki page should not use endl without <ostream>, and your instructor should also teach the use of either '\n' or endl with <ostream>. In many cases, the buffer will be flushed automatically making endl unnecessary, but there are times when it is useful. In those times, you should #include <ostream> to be completely correct, but I don't think I would call someone out on it if they didn't.

  4. #19
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Thanks Daved, that has cleared it up in my mind

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Integer Emulation
    By Elysia in forum C++ Programming
    Replies: 31
    Last Post: 03-18-2008, 01:03 PM
  2. undefined reference
    By 3saul in forum Linux Programming
    Replies: 12
    Last Post: 08-23-2006, 05:28 PM
  3. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 12:55 PM
  4. MSVC Template Constructor/Assignment Errors
    By LuckY in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:57 PM
  5. Question About Linker Errors In Dev-C++
    By ShadowMetis in forum C++ Programming
    Replies: 9
    Last Post: 08-18-2004, 08:42 PM