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

bookOutput

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:

#include <iostream>

int main() {
    std::cout << "I love C++!";
    return 0;
}

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

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 3.33

bookOutput

Swipe to show menu

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:

#include <iostream>

int main() {
    std::cout << "I love C++!";
    return 0;
}

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
some-alt