Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Output | Basics
Introduction to C++
course content

Course Content

Introduction to C++

Introduction to C++

1. Basics
2. Variables
3. Conditional Statements
4. Loops
5. Intro to Arrays

book
Output

To print something in C++ we will use the object cout with the operator <<. The message you want to output must be enclosed with double quotes. For example:

1234567
#include &lt;iostream&gt; using namespace std; int main() { &nbsp&nbsp&nbsp&nbspcout << "I love C++!"; &nbsp&nbsp&nbsp&nbspreturn 0; }
copy

To get the same result, you can also write the code without using namespace std:

Pay attention that you can use the multiple insertion operator and add as many cout objects as you want:

12345678
#include &lt;iostream&gt; using namespace std; int main() { &nbsp&nbsp&nbsp&nbspcout << "I love programming! "; &nbsp&nbsp&nbsp&nbspcout << "I love C++" << " and " << "Python!"; &nbsp&nbsp&nbsp&nbspreturn 0; }
copy

Every cout object or << operator doesn’t write your code to a new line.

question-icon
Print the message "Have a good day!":

#include <iostream>
using namespace std;

int main() {
    
<< "Have a good day!";
    return 0;
}
Have a good day!

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 2
We're sorry to hear that something went wrong. What happened?
some-alt