---
title: "Why is \"using namespace std;\" considered bad practice?"  
description: "Why is \"using namespace std;\" considered bad practice?"  
author: "Utpal Vishwas"  
published: 2023-07-07  
updated: 2023-07-10  
canonical: https://www.mindstick.com/forum/158990/why-is-using-namespace-std-considered-bad-practice  
category: "visual c++"  
tags: ["c++", "programming language"]  
reading_time: 2 minutes  

---

# Why is "using namespace std;" considered bad practice?

Why is "using [namespace](https://www.mindstick.com/articles/12552/namespace) std;" considered bad [practice](https://yourviews.mindstick.com/story/1498/terrific-benefits-of-a-morning-meditation-practice)?

## Replies

### Reply by Aryan Kumar

Using the `namespace std` is considered bad practice because it can make your code less readable and less maintainable. When you use the `namespace std`, you are importing all of the names from the `std` namespace into the current namespace. This can make it difficult to determine where a particular name is coming from, and it can also make it difficult to find the definition of a particular name.

For example, consider the following code:

C++

```plaintext
#include <iostream>

int main() {
  std::cout << "Hello, world!";
  return 0;
}
```

In this code, the `cout` object is being used to print the text "Hello, world!" to the console. The `cout` object is defined in the `std` namespace, so when we use it in our code, we are actually using the `std::cout` object.

However, if we use the `namespace std` directive, we can simplify our code as follows:

C++

```plaintext
#include <iostream>

using namespace std;

int main() {
  cout << "Hello, world!";
  return 0;
}
```

In this code, we are importing all of the names from the `std` namespace into the current namespace. This means that we can now use the `cout` object without having to prefix it with the `std::` namespace qualifier.

While this may seem like a convenient way to write code, it can actually make your code less readable and less maintainable. If you are using the `namespace std`, it can be difficult to determine where a particular name is coming from. For example, if you see the code `cout << "Hello, world!"`, you may not know if the `cout` object is defined in the current namespace or in the `std` namespace.

Additionally, using the `namespace std` can make it difficult to find the definition of a particular name. If you are trying to find the definition of the `cout` object, you will need to search through the `std` namespace. This can be time-consuming and error-prone.

For these reasons, it is generally considered bad practice to use the `namespace std`. If you need to use names from the `std` namespace, it is better to prefix them with the `std::` namespace qualifier. This will make your code more readable and more maintainable.


---

Original Source: https://www.mindstick.com/forum/158990/why-is-using-namespace-std-considered-bad-practice

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
