Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CPP-Cheatsheet/README.md
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
71 lines (50 sloc)
2.18 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CPP-Cheatsheet | |
for the boys, for the boys | |
```cpp | |
Hello and welcome to the beginning of my C++ Cheatsheet; think of this as my Christmas present. | |
Through this, I figured it would be a great idea to have a centralised area for anything related to C++ | |
that would have otherwise flown over your heads during a lecture. | |
Remember that I am always going to be here to help and | |
will continue to work on this as the degree continues. | |
``` | |
# main.cpp: | |
```cpp | |
First and Foremost, lets establish the elephant in the room, | |
the one thing that every Programmer learns how to do | |
(write Hello World to the Console) | |
The way in which it works can go a variety of ways. | |
Since C++ is often referred to as a superset of C, | |
it uses a lot of the C syntax as well as some of it's own libraries | |
``` | |
# NOTE: | |
``#include <iostream>`` is specific to C++ only | |
```cpp | |
Due to this cross-compatibility, that means that libraries such as "stdio.h" and "stdint.h" | |
can be used in both C/C++ programs | |
``` | |
<p align="center"> | |
<img width="700" height="300" src="images/hello/hello.png"> | |
</p> | |
```cpp | |
The use of the <iostream> library is the way that C++ declares standard input and output. | |
The thing that provides this library with the distinction with C libraries of | |
a similar nature is that C++ uses specific keywords to handle various | |
char oriented tasks such as cout for character output and cin for character input | |
Another way of writing "Hello World" to the Console is through using | |
the namespace std as demonstrated below. | |
There is not really much distinction between this and the previous example | |
other than the fact that you are eradicating any reason to include std::cout. | |
Instead in it's place, you are declaring when the comsole stops writing | |
that line which the previous example does anyway. | |
``` | |
<p align="center"> | |
<img width="600" height="275" src="images/hello/hello_std.png"> | |
</p> | |
```cpp | |
In most base cases, you would only ever have to declare using this namespace if you | |
plan on using any of the pre-requisite namespaces the libraries has such as | |
std::string, std::getchar, and std::int32_t - just to name a few examples | |
``` | |
<p align="center"> | |
<img width="400" height="300" src="images/hello/namespace_eg.png"> | |
</p> |