1. This forum is in read-only mode.

what is "endl" in C++ ?

Discussion in 'Non-Emulation Help' started by Neon32, Dec 29, 2012.

  1. Neon32

    Neon32 Neo-Noir

    can someone tell me what is "endl" in C++ .

    i googled it and found all kind of technical and mechanical explanations :-\

    so can someone please tell me this in a human understandable form ? please ?

    Thanks in advance
     
  2. Loonylion

    Loonylion Administrator Staff Member

    end line
     
  3. necr0

    necr0 Well-Known Member

    That's 'human understandable'.
     
  4. Dark Infernape

    Dark Infernape Raiden 雷電

    Hey Neon32 are you learning C++ in class or are you just trying to learn to use it by yourself...?

    they are teaching C++ in my class now....i learned C, SQL & Java Netbeans in my last semester....
    going to learn Oracle too this sem,have no idea what that is though... :)
    Im soo excited, by the end of college im gonna learn half of the best Programming languages out there... :)
     
  5. Loonylion

    Loonylion Administrator Staff Member

    oracle is a database system.

    I'm somewhat surprised you've been taught both C and C++ considering C++ has pretty much replaced C.
     
  6. Dark Infernape

    Dark Infernape Raiden 雷電

    Yeah had to learn C too...
    I keep writing "printf" and "scanf" instead of "cout" and "cin"....
    Happens to me everytime...
    I think C was taught for us to get an idea how C++ works...
     
  7. Neon32

    Neon32 Neo-Noir

    can some one tell me where do we use this endl; pls dont tell that we use t to end lines :)
     
  8. Loonylion

    Loonylion Administrator Staff Member

    you use it on the end of a cout to make the next cout start on a new line
     
  9. Neon32

    Neon32 Neo-Noir

    for that cant we simply use \n ?

    or cascade the cout it to the next line ?
     
  10. Hypr

    Hypr Well-Known Member

    Both "\n" and "endl" works. And yes, you can have multiple lines displayed with a single "cout" command through the use of "endl".

    Example:

    cout << "This is the first line." << endl << "This is the second line." << endl << "This is the third line" << endl;
     
  11. Dark Infernape

    Dark Infernape Raiden 雷電

    Cascading!
     
  12. Neon32

    Neon32 Neo-Noir

    i tried this on my own and didnt found much difference between \n or endl; .

    thanks for all those who replied to it :)
     
  13. Loonylion

    Loonylion Administrator Staff Member

    I am not very familiar with C/C++, however it is possible that there is actually a difference between \n and endl.

    Basically there are multiple ways of ending a line, and different OSes use different methods. *nix uses a linefeed character (ASCII character 10) while Windows uses two characters, carriage return (ASCII character 13), followed by a linefeed (ASCII character 10), which is why neither can properly open files created by the other without the file being converted first. In PHP, \n produces a linefeed, whereas on Windows you would need to use \r\n in order to get the line break, and other OSes use other combinations. This makes it hard to write portable PHP code, so we have an alternative, PHP_EOL, which produces whichever line ending the host system uses. C++'s endl may be similar to PHP_EOL in that it is portable and its output is dependent on the target system.

    EDIT: clarification
     
  14. Neon32

    Neon32 Neo-Noir

    thanks Loony .