View Poll Results: Pick a operator

Voters
34. You may not vote on this poll
  • "\n"

    17 50.00%
  • <<endl;

    17 50.00%

"\n" VS <<endl;

This is a discussion on "\n" VS <<endl; within the A Brief History of Cprogramming.com forums, part of the Community Boards category; newbie alert. /n is the same thing as endl he was aksing a prefrence the onyl differ is that you ...

  1. #16
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    newbie alert.

    /n is the same thing as endl he was aksing a prefrence the onyl differ is that you put /n inside the quotes endl is a seperate thing

    /n example->

    cout << "hello mom /n";
    cout << "hello dad";
    endl example->

    cout << "hello mom" << endl;
    cout << "hello dad";
    the end resualt sshould be the same
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  2. #17
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by Klinerr1
    newbie alert.

    /n is the same thing as endl he was aksing a prefrence the onyl differ is that you put /n inside the quotes endl is a seperate thing

    /n example->

    cout << "hello mom /n";
    cout << "hello dad";
    endl example->

    cout << "hello mom" << endl;
    cout << "hello dad";
    the end resualt sshould be the same
    No, as was stated before:

    endl != \n
    endl == \n + Flush

  3. #18
    Banned Cgawd's Avatar
    Join Date
    Oct 2002
    Posts
    405
    yah, whos the newb now punk

  4. #19
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    i like...

    <<endl;
    simply cause i get lazy and its easier for this ol' fart to type that than other.
    PEACE OUT!
    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  5. #20
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    ah well as someone with tons of brain power once said "learn something new a day"
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  6. #21
    Banned Cgawd's Avatar
    Join Date
    Oct 2002
    Posts
    405
    lol if they had tons of brain power, they might have used a lil grammar and said "Learn something new every day"

  7. #22
    Registered User
    Join Date
    Dec 2001
    Posts
    88
    i use newl - which simply returns '\n'

    I read some performance issues on gcc2.95
    in which '\n' was 60 times faster than endl - so I thought, why use endl??

    a flush is made when the buffer is full - in most cases that's enough.

    Only sometime (if I write to files) it is important to flush, because the program may crash and then the file would be empty...
    Hope you don't mind my bad english, I'm Austrian!

  8. #23
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I don't think you can say which is better because they are different.
    Simply if you need to flush the buffer use endl, if you don't use '\n'.
    it's that simple.

  9. #24
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    I have never really had much of a need to flush the buffer, so I just use them like this:

    If it is a string, use \n, if it is after a variable, use endl.

    Ex:

    cout << "Hello, World! \n";

    cout << myVar << endl;

    Even though endl flushes the buffer, that is not taught in schools. The only thing that is taught in schools is that it goes to the next line, and so that is what people use it for. That is what I have always used it for, and so that's how I use \n and endl.
    My Website

    "Circular logic is good because it is."

  10. #25
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Originally posted by ammar
    I don't think you can say which is better because they are different.
    Simply if you need to flush the buffer use endl, if you don't use '\n'.
    it's that simple.
    but..... I thought if you wanted to flush something (which solves all IO problems) you use fflush(stdin); Am I mistaken?



  11. #26
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    i'll use endl then...

    btw, newb alert yourself :P

  12. #27
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    All this discussion and noone has mentioned that stdout is unbuffered, hence no need for endl unless couting to a file, no?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  13. #28
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Sebastiani
    All this discussion and noone has mentioned that stdout is unbuffered, hence no need for endl unless couting to a file, no?
    but how will you know if you're outputting to a file or to a screen or whatever? all you know is that it's stdout.
    hello, internet!

  14. #29
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, obviously. But in most cases, stout is directed to a terminal, and anyway, if otherwise, the programmer would know in advance (hopefully!).
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  15. #30
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    when i use C++ Ostreams which is very rare i use 'endl', other wise i use '\n'.

    >All this discussion and noone has mentioned that stdout is unbuffered

    since when? i think this is imp dependant.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-06-2008, 02:43 PM
  2. differnce between endl and "\n"
    By BEN10 in forum C++ Programming
    Replies: 2
    Last Post: 07-19-2008, 11:08 AM
  3. Blank lines "\n"
    By Coding in forum C++ Programming
    Replies: 15
    Last Post: 02-18-2008, 08:56 PM
  4. tutorial confusion <<endl;
    By ikke in forum C++ Programming
    Replies: 5
    Last Post: 05-22-2003, 09:39 AM
  5. <<'\n' vs <<endl
    By Panopticon in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2003, 10:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21