"\n" or endl

This is a discussion on "\n" or endl within the C++ Programming forums, part of the General Programming Boards category; I for some reason can't get endl to work. if i try it i get the following error: [Linker Error] ...

  1. #1
    In The Light
    Join Date
    Oct 2001
    Posts
    598

    "\n" or endl

    I for some reason can't get endl to work. if i try it i get the following error:
    [Linker Error] Unresolved external 'std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\PROJECTS\FUNC.OBJ.

    when i change endl for "\n" i get the expected result. Below is a sample of the code that produced the above error:::::

    //---------------------------------------------------------------------------

    #include <vcl.h>
    #include <iostream.h>
    #pragma hdrstop

    //---------------------------------------------------------------------------

    //#pragma argsused

    double first( double a, double c );
    double second( double b, double a );
    double third( double a, double b, double c );
    double fourth( double a, double b, double c );

    double main(int argc, char* argv[])
    {
    double a;
    double b;
    double c;
    //send this input to other functions

    cout<< "Enter a number (a): ";
    cin >>a;
    cout<< "a = " << a << endl; // this line causes the
    // linker error

    cout << "Enter another number (b): ";
    cin >> b;
    cout<< "b = " << b << "\n";

    cout << "Enter another number (c): ";
    cin >> c;
    cout<< "c = " << c << "\n";

    //get this back from other functions------
    -------------------other stuff that works.
    My questions are,
    1. is this a function of iostream.h?
    2. what is the prefered method of advancing to the next line?

    Thanks for your time and assistance

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    49

    endl

    Use endl. Much better /n is more oriented(?) towards C, not C++... and yes, I know there the same thing with more commands "blah blah" but oh well. Go with your prefrence. I like endl better, but you may find /n easier to use. Whatever
    -Kavity
    i'm not stupid, just a little short on brains.
    Kav's game!
    Featuring:
    # - Goodguy mc goodguy
    * - Bad guy mc badguy
    $ - Princess Mc Cess
    @ - Mcdonalds Mc chicken! mmmmmm

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    endl is a manipulator, when inserted into an output stream, inserts a newline character and then flushes the buffer.

    \n is only a new line character.

    Other manipulators are ends when inserted into an output stream, inserts a null terminiator character. flush when inserted into an output stream, flushes the output buffer no new line character inserted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. differnce between endl and "\n"
    By BEN10 in forum C++ Programming
    Replies: 2
    Last Post: 07-19-2008, 11:08 AM
  2. endl or \n ?
    By BlackSlash12 in forum C++ Programming
    Replies: 38
    Last Post: 08-26-2007, 06:17 AM
  3. endl or \n ?
    By plain in forum C++ Programming
    Replies: 5
    Last Post: 09-01-2006, 02:50 PM
  4. Endl - Undeclared identifier.
    By MipZhaP in forum C++ Programming
    Replies: 9
    Last Post: 03-03-2005, 11:01 AM
  5. endl vs \n
    By Chewbacca in forum C++ Programming
    Replies: 5
    Last Post: 09-08-2002, 01:42 PM

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