Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre 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!

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 2

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Awesome!

Completion rate improved to 3.33

bookOutput

Glissez pour afficher le 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!

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 2
some-alt