As I believe that knowing C++ will come in handy in the future I have taken upon myself to learn this hellspawn of a language.
In the first week I have learned the absolute bare minimum of any coding language.
The “Hello World!”
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}
What I learned from this:
- This will be painful to learn
- Every code in C++ should start with #include <iostream>
- #include meaning go grab (file) and include it
- <iostream> – the file that contains input/output tools
- using namespace std; – I want to use the standard library tools without typing the full name every time
- instead of
std :: cout << “Hello”; - shortens to
- cout << “Hello”;
- instead of
- semi colons are a must and will haunt me in the near future
- to end a statement I should use
- return 0;
- Other things:
- int – return type. main returns an integer to the operating system when the program finishes.
- main – a special reserved function name that the OS looks for to start the program
- () – the parameter list.
- can include:
- int argc
- char*
- argv[]
- etc
- can include:
- {} – where the code goes into
Other functions that was learned in the first week of C++
- cout is pronounced as see out
- cin is for user input
- cin >> x;
- >> – for input
- int x – to define x
- ; – the damn semi colon
- cin >> x;
- // can be used anywhere as long as it isn’t literally in the middle of the code (eg: cou//t), it is used for comments
- Types of variables
- int – integers (whole numbers)
- int number = 67;
- cout << number;
- output: 67
- double – floating point numbers (2.12 etc etc)
- double decimalNumber = 6.7;
- cout << decimalNumber;
- output: 6.7
- char – single characters (lower and upper case)
- char character = E;
- cout character;
- output: E
- string – text
- string wholeText = Meme
- cout << wholeText;
- output: Meme
- bool – true or false
- bool bullShit = true;
- bullShit is true
- bool bullShit = true;
- int – integers (whole numbers)
Leave a Reply