Use namespaces to organize code and prevent naming conflicts.
A namespace is a feature in C++ used to group related declarations (functions, classes, variables, etc.) under a single name. This helps to avoid naming conflicts, especially in large projects or when using multiple libraries. For example, two different libraries might both define a class named `List`. Without namespaces, the compiler wouldn't know which one to use. By placing each `List` class inside its own namespace (e.g., `MyLib::List` and `TheirLib::List`), the ambiguity is resolved. To define a namespace, you use the `namespace` keyword: `namespace MyNamespace { ...declarations... }`. To access a member of a namespace, you use the scope resolution operator `::`, like `MyNamespace::myFunction();`. The C++ Standard Library is entirely contained within the `std` namespace, which is why you need to write `std::cout` and `std::vector`. The `using` directive allows you to bring a specific name, or the entire namespace, into the current scope to avoid having to repeatedly type the namespace prefix. For example, `using std::cout;` lets you just write `cout`. The statement `using namespace std;` brings all names from `std` into the current scope. While convenient for small programs, this is generally discouraged in header files and larger projects as it can re-introduce the very naming conflicts that namespaces were designed to prevent.