-
"\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
-
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
-
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.