Back to Curriculum

4. Namespaces

What are Namespaces?

A namespace provides a solution for preventing name conflicts in large projects. Imagine you are working on a team, and you and another developer both create a function called print(). How does the compiler know which one to use?

Namespaces solve this by acting like a "last name" for your code. The functions and variables in the C++ Standard Library are all in a namespace called std.

That's why we've been writing std::cout and std::string. We are telling the compiler to use the cout and string that belong to the std namespace.

🎉

Lesson Complete!

Excellent! You now understand namespaces and how to use the `using` directive.

Back to Curriculum
main.cpp
Output
Click "Check Answer" to run your code.