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++ /

Object-Oriented Programming Language Examples

C++ /

Object-Oriented Programming Features

C++ /

C++ Program to Find Quadratic Equation Roots

‹ Object-Oriented Programming Language Examples› Sum of Digits of a Number C++ Program

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version