Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out



First Line Of C++

In this write-up, you will learn how to set up and write the first line in c ++ and gain a basic understanding of c ++

Intro

C++ is a powerful object-oriented programming language mainly used for game programming, software engineering, data structures, developing browsers, operating systems, applications, and more for over forty years. The language is developed in 1985 by Bjarne Stroustrup. C++ is portable and can be used to develop applications that can be adapted to multiple platforms. C++ is fun and easy to learn!.


Setting up C++

Before programming, you need to set up the environment on your computer. Today we are using an IDE (Integrated Development Environment) called Code Blocks. Download and install the MinGW-setup.exe file.

Hello World

Let's open code blocks create our first program. Go to File > New >Empty. Then Go to File >Save File as, and save the file as "first.CPP" 

NOTE: The extension .cpp is important

Now we can start writing our first program.

Write the following C++ code and save the file.

Make sure to use lowercase letters otherwise, your code will not work

Then click the green run button to execute the code.

You will get the output as shown below

Let's break the code down

Line 1: #include<iostream> 

iostream is a header file or a collection of some code that help us to write code more easily. iostream contains information about the basic input/output operations such as printing something to the console etc. In this line, we are telling the compiler that "Hey compiler, I want to use the header file iostream in my code" So the compiler will include the header file.

Line 2: It's just a blank space. We use it to make our code more readable. The compiler will ignore this line.

Line 3: using namespace std;

using namespace means std means that we can use the names for objects and variables from the standard library. Did you notice that (;) semicolon at the end?. It's used to end every c++ statement.

Line 5: int main()

This is a function. The compiler will execute the code written inside the {} next to it.

These things are pretty much the same in all c++ programs.

Line 7: cout<<"Hello World";

This line of code prints Hello World to the console. cout (c-out) tells the compiler to output something to the console window. << is an I/O operator called put to or insertion operator. It tells the compiler to transfer the given value (In this case "Hello World") from the RAM to an output device( in this case console). " "  is used to declare a string or text. Then ; to end the line.

Thanks

Thank you all for reading this write-up, Hope you enjoyed this. Stay tuned for more content. 

Connect with me on Instagram GitHub linkTree



X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.