0

What if we don't use "using namespace std".. Error occurs yea. But i want to know why.

31st Jan 2018, 7:24 PM
saurabh kumar
saurabh kumar - avatar
2 odpowiedzi
+ 3
In c++ everything from the standard library is encapsulated in the namespace std so it is not enough to include the file from which a function was declared you need to specify that it comes from the namespace std, this can be done in 3 ways: lets take cout as an example 1. you could write std::cout everywhere you need to use it 2. you could write using std::cout at the beginning of the file and just write cout in your code 3. you could write using namespace std and it's like (2) but you are importing the entire namespace and that's bad practice if you don't want to use using namespace std you can use (1) or (2) or you can find other methods for the things you want(other ways to print an output ect.) or come with your own implementation (recommended if you want to learn how to do something) i recommend to use std because it is well optimized and try to avoid (3) and use (1) or (2) as much as possible
31st Jan 2018, 7:56 PM
bogdan
bogdan - avatar
+ 2
As I understood it. using namespace std implements the interface std, which means, you have access to std methods.
31st Jan 2018, 7:40 PM
voidneo