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:
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!"