Skip to main content

Say "Hello, World!" With C++

 Say "Hello, World!" With C++

    I recommend you install CLion IDE and start the Programming after setting up the CMake options under Build, Execution, and Deployment. CLion is a popular integrated development environment specifically designed for C++ development.

Download and Install CLion:

Download and install CLion from the official JetBrains website: https://www.jetbrains.com/clion/download/

Launch CLion:

After installation, launch CLion from your computer's application menu.

Create a New Project:

  • On the CLion welcome screen, click on "New Project."
  • Choose the "C++ Executable" template and click "Next."
  • Enter a name for your project and choose a location to save it. Click "Create."

Configure CMake:

  • CLion uses CMake to manage your project's build configuration.
  • CLion will generate a CMakeLists.txt file for you.
  • You can customize CMake settings in the "CMakeLists.txt" file as needed.

Write Your C++ Code:

  • In the project window, you'll see the "src" folder. Right-click on it and select "New" > "C++ Source File."
  • Enter a name for your source file (e.g., "main.cpp") and click "OK."
  • CLion will open the newly created source file in the editor.

Write and Run Your Program:

  • Write your C++ code in the editor. For example, you can start with a simple "Hello, World!" program.
  • After writing the code, you can build and run it by clicking the green "Run" button on the top toolbar or pressing Shift + F10.

//My First C++ Program
#include <iostream>

int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}

View Output:

The output of your program will be displayed in the "Run" tool window at the bottom of the CLion interface.


Debugging:

CLion offers powerful debugging features. You can set breakpoints, inspect variables, and step through your code to diagnose issues.


Working of C++ "Hello World!" Program

//My First C++ Program
#include <iostream>

int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}

// Your First C++ Program

In C++, any line starting with // is a comment. Comments are intended for the person reading the code to better understand the functionality of the program. It is completely ignored by the C++ compiler.


#include <iostream>

The #include is a preprocessor directive used to include files in our program. The above code is including the contents of the iostream file.

This allows us to use cout in our program to print output on the screen.

For now, just remember that we need to use #include <iostream> to use cout that allows us to print output on the screen.


int main() {...}

A valid C++ program must have the main() function. The curly braces indicate the start and the end of the function.

The execution of code beings from this function.


std::cout << "Hello World!";

std::cout prints the content inside the quotation marks. It must be followed by << followed by the format string. In our example, "Hello World!" is the format string.


Note: ; is used to indicate the end of a statement.


return 0;

The return 0; statement is the "Exit status" of the program. In simple terms, the program ends with this statement.

Remember that C++ development involves learning the language syntax, concepts, and best practices. You can use online resources, tutorials, and courses to enhance your C++ programming skills. As you become more comfortable with CLion and C++, you can start working on more complex projects and exploring advanced features of the IDE.

Prepared by: Malinda Gamage -> LinkedIn Profile






Comments

Popular posts from this blog

Unraveling the Apache Hadoop Ecosystem: The Ultimate Guide to Big Data Processing πŸŒπŸ’ΎπŸš€

In the era of big data, organizations are constantly seeking efficient ways to manage, process, and analyze large volumes of structured and unstructured data. Enter Apache Hadoop , an open-source framework that provides scalable, reliable, and distributed computing solutions. With its rich ecosystem of tools, Hadoop has become a cornerstone for big data projects. Let’s explore the various components and layers of the Hadoop ecosystem and how they work together to deliver insights. Data Processing Layer πŸ› ️πŸ” The heart of Hadoop lies in its data processing capabilities, powered by several essential tools: Apache Pig 🐷 : Allows Hadoop users to write complex MapReduce transformations using a scripting language called Pig Latin , which translates to MapReduce and executes efficiently on large datasets. Apache Hive 🐝 : Provides a SQL-like query language called HiveQL for summarizing, querying, and analyzing data stored in Hadoop’s HDFS or compatible systems like Amazon S3. It makes inter...

Essential Unix Terminal Commands: A Handy Guide for Beginners πŸ–₯️

  If you're working in a Unix-like environment (like Linux or macOS), mastering the command line is key to unlocking the full potential of your system. The terminal allows you to perform powerful operations by executing commands directly. In this guide, we’ll cover some of the most commonly used Unix terminal commands to help you get started! 1. alias – Create Shortcuts for Commands πŸ”— The alias command allows you to create shortcuts for longer commands, making them easier to type and remember. alias ll= 'ls -la' Here, ll is now an alias for ls -la . You can create any alias you like to save time. 2. at – Schedule a Command for Later ⏰ The at command lets you schedule a command to run at a specified time. at 5:00 PM Enter the command you want to run at 5:00 PM, press Ctrl+D to schedule it. 3. cal – Display a Calendar πŸ“… The cal command displays a calendar for the current month. You can specify a year to view its entire calendar. cal 2024 4. cat – Concatena...

Real-Time Monitoring with tail -f: A Guide to Watching Logs Like a Pro πŸš€πŸ“œ

  Whether you’re troubleshooting a server or just monitoring your app’s health, there’s one command that stands out for real-time log monitoring: tail -f . This simple command can be a game-changer for anyone managing logs in a Linux or Unix environment. Let’s explore how you can make the most of tail -f for real-time log watching. What is tail -f ? 🧐 The tail command is designed to display the last few lines of a text file. By adding the -f option, you tell tail to keep the file open and display new lines as they’re added. This is incredibly useful for tracking real-time log files that are actively being written to, such as server or application logs. In essence: tail -f /path/to/log/file.log The -f flag lets you “follow” the log as new entries are added, giving you a live, scrolling view of what’s happening inside that file. Why Use tail -f ? 🌟 Imagine you’ve just deployed a new version of your application, and you want to watch for errors. Rather than constantly opening...