Hello, World!

Environment Configuration

As the saying goes, to do a good job, one must first sharpen one's tools.

Integrated Development Environment

IDE operation is relatively simple, so beginners generally choose to use an IDE to write code.The most common one in contests is Dev-C++ (this IDE is also generally provided if the contest environment is Windows).

Compiler

Windows

Using a GNU compiler is recommended.You need to download and install MinGW from MinGW Distro.In addition, you can choose the Microsoft Visual C++ compiler on Windows; download and install it from the Visual Studio page.

macOS

Run the following command in the terminal:

xcode-select --install

Linux

Use g++ -v to check whether g++ has been installed.

The following command can be used to install it:

sudo apt update && sudo apt install g++

Compiling Code on the Command Line

After becoming proficient, some programmers also use the more flexible command line to compile code, so that they do not depend on an IDE and instead use a familiar text editor to write code.

g++ test.cpp -o test -lm

g++ is the compiler for the C++ language (the compiler for the C language is gcc), -o is used to specify the name of the executable file, and the compilation option -lm is used to link the mathematical library libm, so that code using math.h can compile and run normally.

Note: C++ programs can compile and run normally without -lm.The C++ compilation options for NOI/NOIP problems over the years have all included -lm, so it is included here as well.

First Program

Let us begin the journey into C++ with this sample program~

Note: Remember to enable the English input method before writing.

C++ language

#include <iostream>  // Include the header file

int main() {                     // Define the main function
  std::cout << "Hello, world!";  // Use the cout function in the standard namespace
  return 0;  // Return 0 and end the main function.The compiler generally adds this line automatically, so it can usually be omitted
}

C language

#include <stdio.h>  // Include the header file

int main() {                // Define the main function
  printf("Hello, world!");  // Output Hello, world!
  return 0;                 // Return 0 and end the main function
}

Note: C is provided here for reference only. C++ is basically compatible with C and also has many new features that can help contestants work much more efficiently in contests.See Differences between C++ and Other Commonly Used Languages for details.

This content comes from OI Wiki: Hello, World!. See the original for authors and revision history. AIOJ has adapted the formatting, in-site links, and resource paths.

Content is shared under CC BY-SA 4.0 and SATA license; additional terms are governed by the original notice. Thanks to the OI Wiki authors and contributors; per the SATA terms, please visit the OI Wiki repository and star it to show your support.