Confusing About This Topic

I had some confusion about this topic which i don’t really understand.

  1. At 1st, we typed an #include which means before every code was read(#), we should include a library which contains all the codes that we needs? So what if we didn’t use the library in the 1st place?

  2. I was a bit confusing about using namespace std, std stands for standard, then namespace is the library? or std is the library?

Any commends is highly appreciated, thx!

1 Like

I am a noob so this is what i understand sorry if I am wrong
just trying to help :slight_smile:

#include adds an library of already made codes\namespaces in our case we use standard library which is which came with visual studio
this library contains many tried and tested codes\namespaces made by other people so we don’t have to invent the codes our selves
But in this library their are more than one namespace which has the same name so we use the tag std which stands for standard
so even if their are two namespaces with the same name it will ony use the standard one.Std is just a tag so that the namespace which is used in the code is standard.

this is my understanding of this topic and again I am a noob.

2 Likes

Thank You @osama_amir greatly appreciated your reply! Let’s strive hard and worked hard together!

sry for the late reply tho… There isn’t any notification to notify me about your reply…

@AndersonChong if you follow along in the lesson we do run the man() function without the #include and while the program executes nothing happens. Had we tried to use output such as cout our program would not have compiled because the compiler has no idea what cout means. We use the libraries to add prewritten code that has been tested an “included” in the library so that we are not rewriting code that has already been written and works. C++ is what I think is called a tokenized language. Keywords such as cout are ‘tokens’ that point to code in the libraries. Something like that.
As for the second question the instructor pointed out that in the C++ libraries certain commands are grouped together in name spaces to conserver and organize the code libraries for the sake of efficiency. “std” is a namespace that contains common commands with similar spelling and function and is contained in the library . Including this library at the beginning of the file pastes the code for functions like ‘cout’ into our code where we use it.
This part of the reason C++ requires us to ‘link’ and ‘compile’ our code into our code object in C++.
I know this all sounds complicated but believe me I am returning to C++ after 30 years of NOT coding and its much easier then when I was learning this back in the 80’s and had we not had languages like C++ then we would have to write even lower level code every time we wanted to do something on a computer.
I hole this helped.

Privacy & Terms