Quick question about std

This is a discussion on Quick question about std within the C++ Programming forums, part of the General Programming Boards category; In my classes in C++ so far we have been using
Code:
using namespace std;
I see other examples of ...

statement tells the compiler "if you can find a name in the namespace std, use it".

Using

Code:

std::cout << x;

doesn't let the compiler use anything else out of the "std" namespace. Simply put, it's more restrictive.

You can also use:

Code:

using std::cout;

to tell the compiler that "if you need a cout, you may use the one out of the std namespace".

Namespaces in general are intended to avoid "name-collisions" - if you have two items (functions, classes, structs, varables or whatever it may be) with the same name, the compiler [or linker] can potentially pick up either. Namespaces allow us to separte two different "names" that are otherwise the same.

It also can allow us to have alternative versions of something with only the namespace deciding which you get.

In most cases, it's probably completely equal which one we choose to use.

if u dont put "using namespace std;" on top, then you will have to put "std::" in everything below, or the compiler cant recognize the cout<< and other things.

True - if you use anything that is part of the standard library, then you must tell the compiler that you want it to look for things in std namespace one way or another. For relatively small programs, it's usually "best" to use "using namespace std", whilst in a large program it may be better to avoid that.