C++ uses multiple file extensions for both header files and implementation files. The choice of extension influences clarity, tooling, and the ability to distinguish C from C++ code. Modern C++ projects commonly use .hpp and .cpp, but other extensions exist based on historical conventions and toolchains.
.h — legacy and ambiguous
.hpp — recommended for modern C++
.cpp..hh — minimalist C++ style
.cc).Module-related extensions
.ixx, .mxx, .cppm when working with C++20 Modules.The file extension depends on the implementation and on compiler or project conventions. Common extensions for C++ implementation files include:
.C.cc.cxx.c (rare for C++ but possible in mixed projects).cpp.c++.cp*.cpp is the most widely recognized in modern C++ projects.
For modern, long-term C++ codebases:
.hpp for headers..cpp for implementation files.This yields a clear and idiomatic file structure and reduces ambiguity between C and C++ sources.