I’m a novice C++ programmer.
How can I find out the namespace (is this the right word in this context?) for an include like ‘iomanip’ or any other?
When using ‘std::cout’, I don’t know why it’s ‘std’ and not something else.
I hope my question is clear and worth asking.
PS: My first post here 🙂
How did you know that
coutexisted in the first place?Because you’ve read the friendly manual, the language standard, a good book, or an online reference. The same applies to everything: Your documentation or reference will tell you the namespace in which you find your types.
Generally, everything that’s part of the C++ standard library is in the
stdnamespace, but some things may well be in a namespace nested within. Notable examples of nested namespaces arestd::placeholdersandstd::chrono. But you will be told the correct namespaces if you read a good reference.Thanks to @Potatoswatter: Other constructions that use the same scope resolution syntax are static constants of classes. For example, the class
std::ios_basecontains a static member typeseekdirwith static constant valuesbeg,curandend; those can be accessed viastd::ios_base::begetc. Or, since the typestd::iosinherits fromios_base, viastd::ios::begetc.In many ways, a class with only static members is just a glorified namespace, and in the early days of C++ people often used nested classes to “simulate” nested namespaces, which weren’t available at the time. The scope resolution syntax is the same.