MK 4 wrote: |
---|
"When typing in operators, is it always like in english, where there is a space between words everytime? Or do you sometimes not neet to use spaces for the code on the left side of the operator, or on the code on the right side of the operator on that line of code?" |
The use of white-space depends on the context. The majority of the time, white-space is ignored, but this isn't always the case. Identifiers, such as variable/object names, cannot contain spaces, but they can contain numbers, underscores and upper-/lower-case letters. For instance:
In "
int main", "
int" is the type and "
main" is the identifier. If the space were to be ignored, the compiler would see "
intmain" which is something completely different.
See here: http://en.wikipedia.org/wiki/Naming_convention_(programming)#Common_elements
MK 4 wrote: |
---|
"It does seem to matter for the :: scope resolution operator, but fir other ones like += or % seem to be typed with spaces." |
The Scope Resolution Operator (SRO for short) is a completely different operator in comparison to arithmetic operators. If you don't know, the SRO is used to qualify an identifier with a scope as the name implies. Because you're new to C++, I'd recommend not getting too involved with the SRO just yet. Also, white-space between arithmetic operators is usually ignored.
MK 4 wrote: |
---|
"So I use the :: in the first one, Im not sure what the scope resolution operator does. I have a vague idea, but not very clear." |
As I said above, the SRO is used to qualify an identifier with a scope. "
std" is the standard name-space which contains C++'s library. If an identifier is proceeded with an SRO it means that the identifier is nested. In lay terms, the SRO tells the compiler that the identifier on the right-hand side of the SRO is declared within the scope on the left-hand side of the SRO. For example: "
Australia::Steve" can be worded as: "
Steve ::(lives in) Australia".
MK 4 wrote: |
---|
"With the using directive, It gave me a idea of how that worked, tell me If Im wrong:
English grammer: " Timmy said Hi to Suzy."" |
Again, the meaning of "
using" depends on the context. "
using std::cout" tells the compiler to automatically qualify any references to "
cout" with "
std". However, this can cause ambiguities so it's best avoided for now until you understand why.
"
std::cout" sends a message to the standard output stream. Without confusing you, "
cout" is used to display text on the screen; nothing more, nothing less. "
std::cin" is used to get data from the user via keyboard.
MK 4 wrote: |
---|
"The impression that I got, is that that means the computer reads this line of code from right to left???" |
No. In some contexts ("
context" appears a lot in technical writing), however, the compiler does read code from right-to-left, but left-to-right is the norm. The "
<<" operator has different meanings, specifically "
multiply", "
shift-left" and "
output to...". In more advanced C++, this operator can be overloaded so that its meaning changes in different scenarios.
MK 4 wrote: |
---|
"so it goes this object "Game Over!" is being put into cout??" |
That's how programmers read it, but not the compiler. Most of the time, statements make more sense when they're read backwards. For instance: from right-to-left, "
Y.X" can be read as "
X is a member of Y".
MK 4 wrote: |
---|
"and it feeds the entire code
labelled "somecode" into the std::cout, or some other thing like std::cout?" |
No. See this: http://www.cplusplus.com/doc/tutorial/basic_io/
MK 4 wrote: |
---|
"Actually, does the compiler only take cout, and not all of <iostream> ??" |
No. "
include" directives take 1 operand and that's a file name. The directive is replaced with the entire contents of the file that it included. In other words, "
#include <iostream>" is replaced with the contents of the "
iostream" file within the compiler's directory.
See this for more information on everything: http://www.cplusplus.com/doc/tutorial/