Output(Print Text)

 

Using the cout object

As discussed earlier the cout object, together with the << operator, is used to output values/print text.

 

You can add as many cout objects as you want. However, note that it does not insert a new line at the end of the of each object all of them will be printed in a single line.

 

Example:

 

#include <iostream>
using namespace std;


int main() {
  cout << "Demo Code.";
  cout << "I am learning C++.";
  cout << "Print text.";

    return 0;
}

Output:

Demo Code.I am learning C++.Print text.

 

 

New Lines

 

In order to insert a new line after each object declaration \n is used. Or another way to do so is using end1 manipulator

#include <iostream>
using namespace std;
int main() {
  cout << "Demo Code.\n";
  cout << "I am learning C++" <<end1;
  cout << "print text";

  return 0;
}

 

Output:

Demo Code.
I am learning C++
print text

Note: \n is the preferred way to break lines.