need insight

I have come across:


"std::cout: or "std::cin" and others.

Why not the simple:
"cout" or "cin"?

what special function does the prefix "std" perform?

there were instances that i took out the std and the code still runs
closed account (z05DSL3A)
Read up on namespace and scope.
will do that
from what i have read so far, it implies that when i use "using namespace std;" then i can ignore the "std" prefix.

Literally only use "std" prefix when you do not include "using namespace std" in your code.

Did i get the understanding right?
@Phoko this is my understanding as well. Isn't using std::cout or std::cin all over your program unwitty, where you could just use using namespace std; once and for all?
closed account (z05DSL3A)
using Declarations, ie:
1
2
3
using std::cout;
using std::cin;
using std::endl


add names to the scope in which they are declared. The effect of this is:
» a compilation error occurs if the same name is declared elsewhere in the same scope;
» if the same name is declared in an enclosing scope, the the name in the namespace hides it.

The using directive, ie using namespace std;, does not add a name to the current scope, it only makes the names accesable from it. This means that:
» If a name is declared within a local scope it hides the name from the namespace;
» a name in a namespace hides the same name from an enclosing scope;
» a compilation error occurs if the same name is made visible from multiple namespaces or a name is made visible that hides a name in the global name space.

So, prefer Using Declarations to Using Directive but prefer full scope resolution to Using Declarations.

Thank you everyone, all was helpful.
Topic archived. No new replies allowed.