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

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 2

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Awesome!

Completion rate improved to 3.33

bookOutput

Stryg for at vise menuen

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!

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 2
some-alt