C++ newbie q
Results 1 to 8 of 8

Thread: C++ newbie q

  1. #1
    Senior Member
    Join Date
    Nov 2002
    Posts
    339

    C++ newbie q

    My question is should I end my output lines with std::end1 or '\n' and why?

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    4,786
    \n moves the output to a new line, std::end1 not only starts a new line but flushes out the buffer.

    ive never had occasion to use std::endl. not being a programmer by trade what i write never requires this.
    Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”

  3. #3
    Senior Member
    Join Date
    Oct 2001
    Posts
    186
    i got in the habbit of ending with \n Ex. cout << a << '\n';
    but you can do either. also you should'nt have to type std::endl if your using namespace std or a using dirrective such as using std::endl; . But i cant recall ever having to do that to use endl.
    Ben Franklin said it best. \"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.\"

  4. #4
    Junior Member
    Join Date
    Nov 2002
    Posts
    13
    c++ style is really std:endl , but it really depends on the situation and doesn't matter that much.
    everyone seems to like /n here, well I like std:endl and use it way more often.

  5. #5
    Senior Member
    Join Date
    Jan 2003
    Posts
    3,914
    I've learned C++ rather crudely on my own.. so this is probably horribly wrong, but i always use. cout << "Text Goes Here" << endl

  6. #6
    Senior Member
    Join Date
    Nov 2002
    Posts
    393
    No endl is a great way to keep the memory clean. The buffer, as Tedob1 said.
    In turbo C++, i have to inlclude another header file, i'm not sure about what you are using.
    \"I have a 386 Pentium.\"

  7. #7
    () \/V |\| 3 |) |3\/ |\|3G47|\/3
    Join Date
    Sep 2002
    Posts
    744
    What Tedob1 said is correct. I don't know about the rest of you but I use both 'endl' and '\n'.

    \n (newline) is an escape sequence -- like a carriage return. It simply moves your cursor to the next line for printing. I use this a lot when I have some heavy formatting to do.

    endl is a stream manipulator. It advances output to the next line and flushes the buffer.

    Try checking out msdn you may find some of the answers to your questions there.

    Go Finland!
    Deviant Gallery

  8. #8
    IT Specialist Ghost_25inf's Avatar
    Join Date
    Sep 2001
    Location
    Michigan
    Posts
    648
    useing endl is like hitting enter on the keyboard it will send the cursor to the next line. to end a line being a int, float, cout, or cin statement im most cases use ; Ive only been in programming class for three weeks now and all my programs ended with ; even with the return 0; statement. only time i entered std was at the beginning where i entered

    # include <iostream>
    using namespace std;
    int main ( )

    hope I helped out.
    S25vd2xlZGdlIGlzIHBvd2VyIQ

Posting Permissions

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