std namespace

how come i dont have to include a file with the std namespace?
is it just automatically included by the compiler?

and also when i include a library like the <thread> library
i have to use the std namespace to access it (std::thread)
but doesn't this mean that the thread library is already inside the std namespace? why do i have to include it then?
Last edited on
closed account (1vD3vCM9)
1. Im not sure, but I'm pretty sure that yes.
2. Again, not sure, "std" stands for standard library, so I think thats a yes
Hi,

When one includes a system header file, it has things defined in it which belong in the std namespace, so only those specific things are available, not the whole std namespace . That is better than implicitly bringing in the entire namespace into the global namespace because std is huge: all of the STL belongs to it. One still uses the scope operator :: to access things in it, because that is the purpose of namespaces: to separate various names to avoid conflicts.

It's the same with your own header files: you only include the ones you need. Ideally one should put their own code into it's own namespace/s

Hope this helps :+)
An standard include file usually only defines the classes and functions that are required to use items that are defined in the standard library.

also when i include a library like the <thread> library
i have to use the std namespace to access it (std::thread)

Yes all standard C++ classes are within the standard namespace. And note to actually use the std::thread library you might need to add the thread library to your compile line since this may or may not be in the "main" standard library.

Perhaps you should study up on the purpose of namespaces since you don't understand the difference between using something in a namespace and including headers.

http://en.cppreference.com/w/cpp/language/namespace

Topic archived. No new replies allowed.