Hello, World!
Environment Setup
A craftsman must sharpen his tools to do his work well.
Integrated Development Environment
IDEs are relatively simple to operate, and beginners often choose IDEs to write code. In competitions, Dev-C++ is the most common (if the exam environment is Windows, this IDE is usually provided).
Compiler
Windows
It is recommended to use the GNU compiler. You need to download and install MinGW from MinGW Distro. Alternatively, on Windows, you can also choose the Microsoft Visual C++ compiler, which requires downloading and installing from the Visual Studio page.
macOS
Execute in the terminal:
1 | |
Linux
Use g++ -v to check if g++ is installed.
You can install it with the following command:
1 | |
Compiling Code in the Command Line
Once proficient, some players prefer using the more flexible command line to compile code, eliminating dependency on an IDE and allowing them to write code with their favorite text editor.
1 | |
g++ is the compiler for the C++ language (the C language compiler is gcc), -o is used to specify the filename of the executable, and the compilation option -lm is used to link the math library libm, enabling code that uses math.h to compile and run normally.
Note: C++ programs do not require -lm to compile and run normally. However, the C++ compilation options for past NOI/NOIP problems have included -lm, so it is added here as well.
First Code
Let's begin the C++ introductory journey with this example program~
Note: Please ensure English input mode is enabled before writing.
C++ Language
1 2 3 4 5 6 | |
C Language
1 2 3 4 5 6 | |
Note: The C language is provided here for reference only. C++ is largely compatible with C and offers many new features that can help contestants work more efficiently during competitions. For details, see Differences Between C++ and Other Common Languages.
本页面最近更新:,更新历史
发现错误?想一起完善? 在 GitHub 上编辑此页!
本页面贡献者:OI-wiki
本页面的全部内容在 CC BY-SA 4.0 和 SATA 协议之条款下提供,附加条款亦可能应用