First C++ Code Example and Rundown

c++ code example

Here is the lines of code we will be working with:

#include <iostream>
using std::cout;

int main() {
cout << “Hello!” << “\n”;
}

#include <iostream>

The pound: # of the #include line is a preprocessor directive the tells the compiler to include the library before it begins compiling the program.

<iostream>

iostream is the name of the library which is apart of the C plus standard libraries that come included with any C++ installation.

using std::cout;

This line tells the compiler to use the version of cout provided by the standard library.
cout is an output function, and a number of different libraries could all define their versions of cout.
We want to use the version provided by the standard library, so we include the following:

using std::

This line is included at the top of the program so that the compiler always knows where to find the version of cout that we want.

int main()

main function and is called at the beginning of every C++ program and is at the beginning of every program.
In this case, we’re defining the main function to return an integer value and take no arguments.

cout << “Hello!” << “\n”;

This line prints to the word “Hello” to cout.
The \n character is the new line character. We take this new line character and shift (<<) it to the “Hello” character, then we take that line and shift it to the cout which is the output from the terminal.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chelsea Cruise

Chelsea Cruise

25 Followers

Unity Developer, Software Engineer, Game Designer, Graphic Artist