TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C++

C++ Hello World Program

C++

Introduction

In this post, we will write a small C++ Hello World program and discuss the general structure of a C++ program. In C++ the executable unit is called a function. We will use Code:: Blocks IDE to create a C++ project.

Launch IDE

Launch Code:: Blocks IDE.

https://www.testingdocs.com/launch-codeblocks-ide-on-windows/

Create a Project.

https://www.testingdocs.com/create-new-project-in-codeblocks-ide/

C++ source file

Add C++ source file to the project.

https://www.testingdocs.com/add-c-source-files-in-codeblocks-ide/

Add C++ Code

Let’s write source code for the program.

// Hello World C++ program
#include<iostream>
using namespace std;
int main(){
 cout << "Hello World!" << endl;
return 0;
}

 

The first line is a C++ comment. Comments are ignored by the compiler. They are used to describe the operation of the program.

#include<iostream>

This loads the header file. The include directive instructs the pre-processor to copy the contents of the specified file into the program. The iostream library performs input and output. These are called pre-processor directives. 

using namespace std;

Loads the namespace std. This tells the program will be using objects that are named in a region called std. Namespaces are used to separate sections of the source code.

main()

The main() routine is the start of every C++ program. It is like the entry point where the C++ program execution starts.

cout

cout is the object that writes to the standard stdout device, i.e. the Console window. It is defined in the iostream header file.

endl

endl is the C++ newline character.

<< is used to pass characters from the right to the object on the left. This operator is an insertion operator.

Run the program

Build and Run the program to see the output as shown in the picture.

 

C++ Hello World

 

The return statement returns an integer value to the operating system after the C++ program completion. It is a convention that a zero result from the main indicates that the program ran successfully without any errors.

That’s it. We have successfully run a simple Hello World C++ program.

—

Code::Blocks Tutorials

Code::Blocks Tutorials on this website can be found at:

https://www.testingdocs.com/code-blocks-tutorials/

For more information on Code::Blocks IDE, visit the official website:

https://www.codeblocks.org/

Related Posts

g not found OpenSuse

C++ /

Install GCC C++ Compiler on OpenSuse

sum of digits c program

C++ /

Sum of Digits of a Number C++ Program

C++ /

C++ Program to Find Quadratic Equation Roots

C Class Constructor

C++ /

Define C++ Class Constructor

Create C File Command Line Linux

C++ /

Run C++ Program on Linux

‹ C++ Program to Find Quadratic Equation Roots› Sum of Digits of a Number C++ Program

Recent Posts

  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • RAPTOR Editions
  • Flowgorithm Conditional Breakpoint Statement
  • Flowgorithm Read Numbers from File Example
  • Search Text File Flowchart Example
  • Flowgorithm Turtle Graphics Symbols
  • Draw Circle using Flowgorithm Turtle
  • Draw Parallel Lines using Flowgorithm Graphics

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version