.cpp File Extension
.cpp file contains, how to open and compile C++ source code, how Poly supports it, and how it compares with related source files. File extension details for .cpp
Full Support| File type | C++ source code |
|---|---|
| MIME type | |
| Encoding | Plain text, commonly UTF-8 or another ASCII-compatible encoding |
| Operating systems | Windows, macOS, Linux |
| Opens with | Visual Studio Code, Visual Studio, Xcode, Vim |
| Poly support | Yes. Poly recognizes .cpp as readable C++ source code. |
| Indexed by Poly | Yes. Poly indexes readable source for exact and semantic search. |
| Preview in Poly | Yes. C++ source opens in Poly's code editor with syntax highlighting. |
| Poly agent | Yes. The Poly agent can read and reason about the source text. |
What kind of file is a .cpp?
A .cpp file normally contains source code written in C++. It is human-readable text, not a compiled application. A file may contain functions, classes, templates, preprocessor directives, and comments. In a larger project, each .cpp implementation file and the headers it includes form a translation unit that the compiler processes independently.1
The suffix is a language hint. GCC recognizes .cpp as C++ source that must be preprocessed, alongside conventions such as .cc and .cxx.2 Microsoft tools also treat .cpp as C++ by default. The source has no fixed magic bytes, so software identifies it from the filename, a declared type, or inspection of the text.
There is no dedicated IANA-registered media type for C++ source.3 Systems may use text/plain or the unregistered text/x-c++src. The freedesktop.org shared MIME system associates the latter with C++ source patterns.4 Poly treats .cpp as readable text/plain.
program.c to program.cpp does not translate C into C++. It may instead make a compiler interpret the same text under different language rules.How do I open a .cpp on my computer?
Any text editor can open a .cpp file. Visual Studio Code, Visual Studio, Xcode, CLion, Vim, and Emacs add C++ syntax highlighting and project-aware features. Windows, macOS, and Linux all have editors and C++ toolchains available.
Opening source for reading does not execute it. To build a simple single-file program with a GNU-compatible compiler, you might use:
g++ hello.cpp -o hello
Real projects often depend on headers, libraries, generated files, compiler options, and a build system such as CMake, Meson, or Make. Follow the project's build instructions, and do not compile or run untrusted code outside an appropriately isolated environment.
Poly support for .cpp
Poly opens .cpp files in a read-only, code-friendly viewer with C++ syntax highlighting, word wrap, and in-file search. It indexes readable source for exact and semantic search. You can find a symbol by name or locate code by its purpose. The Poly agent can read the source to summarize classes, explain functions, and help trace likely behavior.
Poly does not compile or execute the code, resolve included headers, or reconstruct the build environment. Keep related headers, build files, and documentation together when search or the agent needs the wider project context.
History of .cpp
Bjarne Stroustrup began the work that became C++ at Bell Labs in 1979. The first version called C++ was used internally at AT&T in August 1983, and the first commercial implementation arrived in October 1985 with the first edition of The C++ Programming Language.5
.cpp became one of several conventions for C++ implementation files. GCC still recognizes .C, .cc, .cpp, .CPP, .c++, .cp, and .cxx.2 The suffix does not identify a C++ language edition, compiler extensions, target platform, or application binary interface, so build configuration remains essential.
Working with .cpp and alternatives
Choose the convention that matches the project and compilation stage:
| File | Typical role |
|---|---|
.cpp, .cc, or .cxx | C++ implementation source |
.h, .hpp, or .hxx | Headers included by C or C++ source |
.ii | C++ source after preprocessing |
.o or .obj | Compiled object code, not readable source |
.ixx or .cppm | Conventions used for C++20 module interface units |
Use the naming pattern already established by the project. Keep source in version control, and preserve the build files that select the compiler, language edition, target, warnings, and linked libraries. A compiler can turn .cpp into object code or an executable, but changing an extension alone never performs that conversion.
Footnotes
- Microsoft. Translation Units and Linkage. Microsoft describes
.cppand.cxxas typical implementation-file extensions and explains independent compilation. ↩ - GNU Project. Compiling C++ Programs. GCC lists conventional C++ source, header, preprocessed-source, and module-interface suffixes. ↩ ↩2
- Internet Assigned Numbers Authority. Media Types Registry. The registry contains no dedicated C++ source subtype. ↩
- freedesktop.org. Shared MIME-info Database Specification. The specification's glob examples use
text/x-c++srcfor C++ source filenames. ↩ - Bjarne Stroustrup. C++ Style and Technique FAQ. Stroustrup dates the first internal C++ version to August 1983 and the first commercial release to October 1985. ↩