Welcome to my c++ introduction! I hope that I do a good job explaining this.
EDIT: I have a new lesson for all to see on Repl talk!
I will post something every Sunday I will try to post something every Sunday.
EDIT: Thanks so much for the cycles(upvotes). It means a lot to me and I will definitely post on Saturday!
Fellow c++ers: If something is incorrect or can be explained better, tell me!
People reading this: Questions? Comment on this post and I will get back to you as soon as possible.
OK, let's get started!
Including files using preprocessor directives
If you've learned another language before, you probably know that you need to include files.
If you haven't, picture this: You are in a library, and you need to borrow a book. You use it in your book report.
To include a file, use this:
- Your first file (credit to @DynamicSquid for making this more clear):
#include <iostream> // used for input and output to the screen. This is a //basic header file.
- Comments(credit to @Highwayman for asking me to add this)
- Comments are used to document what the code does. They won't change the program
- Person: Why use comments if they don't change the program?
- Me: OK, imagine this: You are working for a programming company and you send your giant program(let's say 100,000 lines) to the big boss for review. If you didn't add comments, they would have to figure out all 100,000 lines by themselves!
- Person: Fine, fine, but I want to just program for fun. No one will look at my work, just me. So do I have to put comments then?
- Me: Of course. Say you have a program you've worked on for a looong time(the same 100,000 lines of code). It finally works! Now, you leave it for 2 months or so. Then, you realize that there's something more you want to add to it, so you go back. Now, you have to retrace all your code again! (Real life experience: I ended up deleting some code I had been working on because I didn't understand it after coming back from a vacation. Please don't make this mistake!)
end of offshoot
- Ok, so anyway, let's look at the difference between single and multi-line comments.
//This is a single-line comment. //For each new line you make, //You need a new pair of forward slashes(//) to make it //a comment.
/* This is a multi line comment. You can have as many lines as you want, as long as it is between the /* and the thing you will see right now. */
That's all folks! Tune in next week to learn about the main function!
(insert jazzy music here)