how to classify a variable?

Started by
9 comments, last by Ezbez 17 years, 5 months ago
Quote:Original post by NIAB
well, except what the namespace std is,
and the iostream thing.


"using namespace blarg;" means that everything inside of the namespace titled "blarg" will be taken out of that namespace and put into your regular 'global' namespace. A namespace is a group of code (functions, classes, anything!) that are put into a separate 'box' from the rest of the program. By writing 'using namespace whatever' it takes all the parts of the code out of the box and lets you use it without specifically specifying that it's in the box.

Bad analogy time! I've got a hammer, it is in a box, let's call it "box std". If I want my assistant to get a hammer, I have to tell him where the hammer is! So, I tell him to get me my hammer out of the box std. Now, if I was to tell him to first dump the contents of the box out, then I wouldn't have to tell him to look in the box to find the hammer since it'd already be out. That's what "using namespace std;" does; it dumps box std out onto the ground.

#include <iostream> is a bit simpler. It is telling the compiler to copy the contents of the file "iostream" into your code. iostream contains all the information that is required to use cout, cin and other things. Your compiler provides you with iostream, so you don't have to write that, but you do have to tell it to use the file, otherwise it won't know what cout and cin are.

This topic is closed to new replies.

Advertisement