Let's begin with a step-by-step tutorial on creating and executing your first C++ program.
C++ is a general-purpose programming language that supports both high and low-level programming. It was developed as an extension of the C language and has features that allow for object-oriented, procedural, and generic programming.
Before you start writing C++ code, you need to set up a development environment:
For simplicity, this tutorial will assume you're using GCC on a Linux-like environment.
Open a text editor and type the following code:
#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; } Save this file with a .cpp extension, for instance, hello.cpp.
#include <iostream>: This is a preprocessor directive that tells the compiler to include the header file iostream. This file contains functions of the C++ standard library related to input-output operations.
int main(): This is the entry point of the program. Every C++ program starts its execution from the main function.
std::cout: It stands for "character output", and it's used to display text. It's part of the C++ standard library.
<< "Hello, World!": This sends the string "Hello, World!" to the output stream (usually your terminal or command prompt).
std::endl: This is an "end line" command, equivalent to a newline character.
return 0;: This exits the program and returns a value of 0 to indicate successful completion.
In your terminal or command prompt, navigate to the directory where you saved your hello.cpp file. Type:
g++ hello.cpp -o hello
This tells the g++ compiler to compile the hello.cpp file and produce an executable named hello.
After compiling, you can run the program:
./hello
You should see the output:
Hello, World!
Congratulations! You've just written, compiled, and executed your first C++ program. As you progress, you'll learn more about the powerful features C++ offers, but understanding this simple program is the first step in your C++ journey.
windows-subsystem-for-linux pysftp thread-local dllimport mysql-error-1052 ping synchronous bearing atom-editor mat-file