Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Hello, C++! | Getting Started with C++
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C++ Foundations: An Introductory Course

bookHello, C++!

main.cpp

main.cpp

copy
123456
#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }

The example above is a classic starting point for every C++ programmer. Each line in this simple program has a specific role:

  • The first line, #include <iostream>, tells the compiler to include the input/output stream library. This library gives you access to objects like std::cout, which is used for printing text to the screen;
  • The next part, int main() { ... }, defines the main function. Every C++ program must have a main function, as this is where the program begins running;
  • Inside the main function, the line std::cout << "Hello, World!" << std::endl; sends the text "Hello, World!" to the output stream, which displays it on your screen. The << operator is used to pass the string to std::cout, and std::endl adds a new line after the text;
  • The final line, return 0;, ends the main function and returns the value 0 to the operating system. This is a way of signaling that the program finished successfully.

Even though this program is short, it introduces you to the basic building blocks of every C++ application: including libraries, defining the main function, displaying output, and signaling successful completion.

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 1

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

bookHello, C++!

Swipe um das Menü anzuzeigen

main.cpp

main.cpp

copy
123456
#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }

The example above is a classic starting point for every C++ programmer. Each line in this simple program has a specific role:

  • The first line, #include <iostream>, tells the compiler to include the input/output stream library. This library gives you access to objects like std::cout, which is used for printing text to the screen;
  • The next part, int main() { ... }, defines the main function. Every C++ program must have a main function, as this is where the program begins running;
  • Inside the main function, the line std::cout << "Hello, World!" << std::endl; sends the text "Hello, World!" to the output stream, which displays it on your screen. The << operator is used to pass the string to std::cout, and std::endl adds a new line after the text;
  • The final line, return 0;, ends the main function and returns the value 0 to the operating system. This is a way of signaling that the program finished successfully.

Even though this program is short, it introduces you to the basic building blocks of every C++ application: including libraries, defining the main function, displaying output, and signaling successful completion.

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 1
some-alt