Today I’m going to show you how to do two simple things on C++: create and run a programm and adding a comment to your program.

If you are on Windows, the first thing you need is a text editor where you can create your programs, and another program which works as a terminal, where you will run your programs. So, for the text editor, you can actually use Windows Note Pad, but the UI isn’t friendly at all and it may bore you; so instead, there’s this text editor called Atom which is a great tool with a nice UI. You will enjoy doing your programs on Atom. And the second thing you need is a terminal called Cygwin which will run your programs. You need to install certain things on Cygwin for its proper functionality. Here is a great video that will help you with a step by step installation.

Now that your programming environmet is set, you are ready to start this amazing journey.

When you install Atom, make sure to give it an easy access location within your computer, this will later be very important. Now, when you first open Atom, it looks like this:

This is where the magic starts.
For your first program, you will be able to print (show in the terminal [Cygwin]) a message. 
In C++ and for basic programs, you will have to write this first code:

This gives you the ability to write your program INSIDE the braces { }. Once you have this piece of code, you will want to save it as “NAMEOFYOURPROGRAM.cpp”. The “.cpp” is the most important thing, because it gives the text the characteristic of being a C++ file.

Now that you are done with this, you want to write the message you want the terminal to show when you run your program. So, in order to do it, you need your first command: 
– cout (its C++ way of saying “show this”).

The programm needs to be written in this way:

cout << “The text you want to show” << endl; 

Now you know how to write your very first basic C++ program! 
There’s this other thing called comments that you can add to your program but it won’t affect it. They are useful when you want to explain how you did something in that specific line.
To add a comment, you simply write // and your comment next to it. 

You are now done with your program!

What you want next is to run your program. This will be done on the terminal, Cygwin. 

When you open Cygwin, it kinda looks like any “hacking program” you’ve seen on a movie, which is pretty cool. 

Now, you need to give the terminal the location of your program (that’s why I told you this step was important) and this is done with a command called “change directory” and is written as it follows:

This change of directory is specific for my computer, it will look different with your computer and will depend on where you saved your first program. 

Now that Cygwin knows where is the program you want to run, you need to tell it to compile it. This is done with the command: “g++ YOURPROGRAM.cpp”

This will compile your program. Now Cygwin is able to run your program, and is done with the command “./a.exe”. When you execute your program, Cygwin will do whatever you programmed on Atom. In this case, just some text.

And that’s pretty much it! You are now able to create a C++ file, run your program, and add comments to it. Congrats! 😀

CC BY 4.0 Mastery 1 & 7 by Omar Peza is licensed under a Creative Commons Attribution 4.0 International License.