Welcome back! C++ is a very popular programming language used in almost every company across the world, so let’s talk about the basics of this language, specifically installing it on your machine! It is recommended for MacOS users to make sure you have Xcode installed, here is a link on how to install that:
Xcode - Apple Developer
SwiftUI offers new features, improved performance, and the power to do even more, all while maintaining a stable API…
Starting off we want to install an IDE, this is an integrated development environment, there are many different ones available but we’ll be using Visual Studio Code in this example, so let’s go ahead and install it. Let’s make our way over to the Visual Studio Code website:
Visual Studio Code - Code Editing. Redefined
Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud…
From there, we want to download the specific software for our machine, luckily for us the website will automatically determine which machine we’re on, all we have to do is click the download button here:
Once downloaded you want to install this piece of software just like any other software. Once that is done we will then have to install the C++ extension for this environment, to do so we want to open up the VS Code (Visual Studio Code) app, we want to select the extensions view icon, search up C++ and install this extension:
Awesome! If you want to view the full documentation on Visual Studio Code C++ extension check out their page below:
C++ programming with Visual Studio Code
C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++…
Great! Now a C++ file should always use the extension .cpp, this indicates that the file is a C++ file. Now, let’s say we have a C++ file coded out and we want to run it, well we would need to run it through a compiler.
Installing a Compiler
To install a compiler we’ll need to make sure we don’t already have one installed, Linux and MacOS machines already have a C++ compiler built in. We can make our way over to the Visual Studio Terminal and type in:
This should output the version of your g++ version of your system, if you don’t have g++ installed on your MacOS machine you’ll have to install command line tools, look at the following link to do so:
How to Install Command Line Tools in Mac OS X (Without Xcode)
Mac users who prefer to have a more traditional Unix toolkit accessible to them through the Terminal may wish to…
On Windows we would need to install the MinGW-x64, to install this software we want to use this link down below:
MinGW-w64 - for 32 and 64 bit Windows
Download MinGW-w64 - for 32 and 64 bit Windows for free. A complete runtime environment for gcc. The mingw-w64 project…
At that point you want to verify that the installation went through successfully by typing in the following code:
Awesome, you are now ready to start writing a C++ project, let’s build a very basic C++ script.
Let’s go ahead and do a sample Hello World, this is essentially the code to do so:
using namespace std;
cout << "Hello World" << endl;
We’ll go into more detail about this code in other tutorials, now we want to save this as a .cpp file, so make sure to save it as that file type. Next up, we want to run it in our terminal, let’s start off by compiling the code, to do so we use the following template:
g++ PATH/TO/THE/CODE.cpp -o <any name>
For me this code will look like this:
g++ Users/Desktop/hello.cpp -o hello
Now we want to execute this code, this is the line to do so:
This is what the final code will look like:
Awesome! At this point you should have your C++ environment set up and the ability to run your code as well. I will be making tons of tutorial for C++ which will link to this tutorial, so if you have any improvements to this tutorial please let me know!
if you have any suggestions, thoughts or just want to connect, feel free to contact / follow me on Twitter! Also, below is a link to some of my favorite resources for learning programming, Python, R, Data Science, etc.
Here are some of my favorite courses, books and so much more. Most of these are affiliate links which help me create…
Thanks so much for reading!