Hi! This will be part 1 of an X-part series to learn the basics of C++. C++ is an important language to learn, seeing as everyone already knows java and python, employers will be looking for potential employees with a little more coding languages under their belts, such as C++ and other languages! C++ is a good middle language to learn that will be important in the real world and will help distinguish you from other applicants for a position at a company. We’ll just start off with the basics of this article, so I apologize for the short length, but there should probably be longer and more informative as time goes on and there are more categories to learn!
First, a little history! The first C book was written by Brian Kernighan and Dennis Ritchie, teaching about the language of the father language of C++, was published in 1978. Then, in 1985, Bjarne Stroustrup published a book that described a new language, C++, adding new features to support object-oriented programming, which will make our lives a lot easier as we learn this language! Now into the actual coding...
Starting a program
When you start out a program, it should show to be a
.cpp file. I personally use Microsoft Visual Studio and download the C++ compiler, but another great alternative is repl.it, a great cloud coding website that will help a lot for beginners!
Starting out, you will see the main program. Don’t touch that. You will also see a
#include <iostream>. Don’t touch that ever, it gives you the basic library. Then type in under
using namespace std;. This will help save time and save you from typing out std:: in front of every command you make.
Commenting is an important part of any code, to leave notes for others and yourself on the functionality of the code! To do a single line comment, use
To use a comment with multiple lines, put it in between
In order to make code more readable, you can put in as many whitespaces in between operators at once! Spaces in the program aren’t read by the program, making this possible!
In order to output something to the console, use cout! Using cout one will be able to print out their thoughts or words, or really anything! Using cout <<, one will be able to print out whatever they put after it!