Here's more of what I've learned so far. The basic stuff cont (not basic as in BASIC :))
Whitespace - The compiler mostly ignores blank spaces aka whitespace. Whitespace is used mostly for us humans so we can read the code easier.
#include - This is a preprocessor directive. It tells the program what to include in your program. A file that you include in the program is called a header file. Examples of some header files and how to write them:
// commenting - If you want to comment on some piece of code to make it easier for you or others to understand what it does then type // for a comment that is only one line or /* */ for multiple lined comments. Example:
// This is my comment
/* This is
Functions - A function is a group of programming code that does some work and can return a value. More on functions later, but for now all you need to know is that you need to have a main() function in every program. Example:
using namespace std;
I'm probably repeating myself but get used to that. You'll be repeating yourself in the code many many many times or at least I am. To really understand anything I have to play around with it. Trying different things and seeing if it works. Now onto more basic things.
cout - I didn't mention before that cout is a string literal which means it's literally the characters between the quotes.
cout is an object from the iostream (header file we included in the first program).
<< - The name for this is output operator. Like I said before, it takes whatever is on the open ended side and puts it in the closed end side.
If I wasn't using "using namespace std;" then I would have to attach a prefix to the cout string literal. For example without using namespace std;
std::cout << "Prefix example.";
That std is a namespace which tells the compiler where to look for "cout". In this case the compiler looks for "cout" in the standard library. It's like an area code. Without that area code the compiler wouldn't know where to look for cout.
That is where "using namespace std;" comes into play. This little line of code loads the standard library into the program so you don't have to type an area code every time you want to use cout or anything else from the standard library. I'm sure there are reasons to use a prefix with every line of code, but for what I want to accomplish I think for now it would be much easier if I don't have to type that in every time I want to write an object from one of the libraries. I would have to do that with every single object I used. Example:
std::cout << "Another example." << std::endl;
Since both cout and endl are in the standard library I would have to tell the compiler where both of them were.
This of libraries like this:
There's the standard library. Within that is iostream. Within that is cout.
; - I mentioned this before, but I'll get more techincal this time around.
All statements must end in a semicolon. cout << "blah blah blah" << endl; is a statement so it needs a semicolon. Simple as that. Just like most sentences need a period or some other form of closing punctuation.
This will be explained more when dealing with functions, but for now just think of this as the off button.
So let's wrap up so I don't keep repeating myself next blog entry.
We've learned about:
functions (tiny bit)
cout (a string literal)
I apologize in advance if you really are trying to learn something about C++ by reading this. I'm still learning myself and my thought process is all over the place. I'll try to keep things more organized from now on.
Well to all the little bots that live in the void that is my blog, see you next time.
Same rat channel.
Same rat time.....maybe :D