Namespaces in C++

Hi all,

Question stemming from the related video - when stating “using namespace std;” at the beginning of a block of code, how does the block know what “std” namespace does?

Where is this function kept?
Is it related to also stating "#include "?

Thanks in advance,

Jason

1 Like

See this article for a spot on explanation of namespaces and std in particular: https://link.medium.com/3kg9KlEM1eb
Note that some googeling won’t hurt you and that researching is THE nr. 1 skill to cultivate on your path to becoming an independent and reliable developer. It took me 1 min to find this article, another 3 to read and understand it :wink:
I also recommended to get Medium’s app, as it is a huge resource for Dev’s like you and me.

1 Like

Hey Bhujanga…appreciate you taking the time to answer to my question.

Absolutely agree with you googling doesn’t hurt, as a dev i’ve learnt google is my best friend :slight_smile: and I do normally go down that avenue first…but just wanted to try and engage a bit with the academy community tonight.

Anyway thanks for the tips.

3 Likes

Hi Jason, As far as I understood std is a global namespace, which gets included by <iostream> (Probably means Input Output Stream) which is required by main (root) function to be able to begin with very basic functions, like set (cin) and get (cout) for a computer program.

I support your defense, getting something real on the table in the forums as a return is the most important thing for a community based education system.

Here’s a link I have read about the concept:
https://medium.com/breaktheloop/why-using-namespace-std-is-used-after-including-iostream-dc5ae45db652

And also here about Global Scope and Namespaces
To the Title “The global namespace”
https://www.learncpp.com/cpp-tutorial/2-9-naming-collisions-and-an-introduction-to-namespaces/

Greetings

1 Like