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

Зміст курсу

Introduction to C++

Introduction to C++

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

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:

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!

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 2
some-alt