Thread: C++ Programming
View Single Post
Old 03-09-2005, 04:12 PM   #8 (permalink)
Iron_Cross
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

If the code worked then it's because cout and cin are so common that the compiler did it automatically.

cout (and cin) are both part of the std namespace. A namespace is like a collection of objects and classes. So if you have two classes named Math you could put them in different namespaces.

Say, for example, that I had two classes, bother were called Math. Yet one of them did operations with numbers and the other did operations with strings. Normally I couldn't have two classes both named Math. Because the compiler wouldn't know which one I was refering to. So to fix that, I would put them in different namespaces. String and Number (respectivly) then I could refer the Math class by it's fully qualified name:

String::Math
and
Number::Math

That way the compiler knows which Math class I'm talking about. Now then if I didn't like typing "Number::Math" each time but only wanted to type Math, I could say:
Code:
using namespace Number;
Then I would only have to type Math and not Number::Math. That little statment tells the compiler, "Hey, I'm using the Number namespace, so each time you see a class or object that looks like it comes some namespace, that's the one to use!"
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline