C++ Output (cout <<) C-PLUS-PLUS

C++ Output (cout <<)  

C++ Output (cout <<)

C++ Output: cout <<

The cout object, together with the << operator is used to output values/print text. You can add as many cout objects as you want.

Example

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!";
  cout << "My C++ Program";
  return 0;
}

Output:

Hello World!My C++ Program

New Lines

To insert a new line, you can use the \n character.

Note: Two \n characters after each other will create a blank line.

Example

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World! \n\n";
  cout << "My C++ Program";
  return 0;
}

Output:

Hello World!

My C++ Program

endl

This is another way to insert a new line. With the endl manipulator, you can use a newline.

Example

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!" << endl;
  cout << "My C++ Program";
  return 0;
}

Output:

Hello World!
My C++ Program

Both \n and endl are used to break lines. However, \n is used more often and is the preferred way.

Download free E-book of C-PLUS-PLUS


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries