How to use endl

How can I use endl

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main ()
{
cout << "Hello User, What is your name?" ;
cout << " ";
string name;
cin >>name;
cout << "Hi " << name << "!" ;
cout << " ";



system("PAUSE");
return 0;
}
Print it like you would print any other variable.
std::cout << std::endl;
You're printing a newline to standard output (your monitor in this case), and you're making sure that anything the C++ runtime has buffered in cout is flushed to the screen immediately.
Taken from: http://www.cplusplus.com/reference/ostream/endl/
[endl] inserts a new-line character and flushes the stream.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// endl example
#include <iostream>     // std::cout, std::end

int main () {

  int a=100;
  double b=3.14;

  std::cout << a;
  std::cout << std::endl;              // manipulator inserted alone
  std::cout << b << std::endl << a*b;  // manipulator in concatenated insertion
  std::endl (std::cout);               // endl called as a regular function

  return 0
100
3.14
314


-Albatross
Last edited on
when you ouput ( cout ) instead of say outputting a string , number , or letter you can put the endl macro function.

ex:
1
2
3
4
5
6
7
8
9
10
cout << "Hello," << endl;
cout << "World!" << endl;

//heres just an empty line

cout << endl;

//you can chain them also

cout << endl << endl;


*typo
Last edited on
Topic archived. No new replies allowed.