Learn more about C++ Output

C++ Output (Print Text)

In this article or you can say blog, we shall discuss C++ Output of our C++ code or how we can Print text okay. So for that purpose, we use cout object along with << operator is used to print values or output text okay.

C++ Output

For example:

Let’s look over this code:

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!";
  return 0;
}

Output:

Hello World!

Now 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 output:

For example:

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!";
  cout << "I am learning C++ wih Codelikechamp.com";
  return 0;
}

Output:

Hello World!I am learning C++ wih Codelikechamp.com

Now the question is how can we add a line to our code so it will also add a line in our output for that purpose, we take the help of Escape sequences; see below how you can do that.

New Line in C++ Output

To insert a new line, you can use the \n character: which is Escape Sequences

For example:

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World! \n";
  cout << "I am learning C++";
  return 0;
}

Output:

Hello World!
I am learning C++

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

For example:

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World! \n\n";
  cout << "I am learning C++";
  return 0;
}

Output:

Hello World!

I am learning C++

NOTE: You can try more escape sequences for you own purpose or need here is the list you can go through it.

Escape Sequences List

Escape sequenceCharacter represented
\aAlert (Beep, Bell) (added in C89)
\bBackspace
\eescape character
\fForm feed Page Break
\nNewline (Line Feed)
\rCarriage Return
\tHorizontal Tab
\vVertical Tab
\\Backslash
\’Apostrophe or single quotation mark
\”Double quotation mark
\?Question mark (used to avoid trigraphs)
ALL ESCAPES SEQUENCES LIST

Link: https://Codelikechamp.com

Medium Link: Follow me on Medium

Linkedin Link: Follow me on Linkedin

🤞 Don’t miss any latest posts!

Please subscribe by joining our community for free and stay updated!!!

IF YOU HAVE ALREADY SUBSCRIBED JUST CLOSE THIS FORM !

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top