Back to results for “Namespaces”
C++ › Namespaces

What is a namespace alias?

Intermediate

Answer

A namespace alias creates a shorter name for a long or nested namespace, improving readability without a broad using-directive. It's commonly used for deeply nested namespaces or to switch implementations by aliasing one namespace to a chosen name.
namespace fs = std::filesystem;
fs::path p = "/tmp";
Real-world example Aliasing std::filesystem to fs keeps code concise while remaining explicit.

Common follow-ups: How does an alias differ from a using-directive? | When is it useful?