C++ is a high-level programming language that is widely used for developing various applications, including video games, operating systems, and scientific applications. One of the first programs that a programmer writes when learning a new programming language is the "Hello World" program, which simply displays the message "Hello World" on the screen. In this article, we'll go over how to write your first C++ program, the "Hello World" example.
To write a C++ program, you'll need a compiler and a text editor. A compiler is a software that translates your code into machine code, which can be executed by a computer. A text editor is a program where you can write and edit code. Some popular text editors for C++ programming include Visual Studio Code, Sublime Text, and Code::Blocks.
Once you have your compiler and text editor installed, you can start writing your "Hello World" program. To do this, open your text editor and type the following code:
#include int main() { std::cout << "Hello World" << std::endl; return 0; }
This code uses the #include
preprocessor directive to include the iostream
header file, which contains the cout
function. The cout
function is used to display the message "Hello World" on the screen. The endl
at the end of the line is a newline character, which causes the next output to be displayed on a new line.
Finally, to run your program, you'll need to save the code to a file with the .cpp
extension and compile it using your compiler. The exact steps for compiling your code will vary depending on the compiler you're using, but in most cases, you can compile it by right-clicking on the file and selecting "Compile" or by using the command line.
Once the code is compiled, you can run the program, and you'll see the message "Hello World" displayed on the screen. Congratulations! You've just written your first C++ program. Now you're ready to start learning more about this powerful programming language.
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.