What is a .cpp file?
C++ Source File · Code and data · Bjarne Stroustrup / Bell Labs · 1985
A .cpp file is C++ source code, an extension of C that adds classes, templates and a large standard library. It is used for games, high-performance software, browsers and desktop applications.
What is a .cpp file used for?
C++ keeps C's speed and low-level control while adding object-oriented and generic programming. A compiler like g++, Clang or MSVC turns a .cpp file into a fast native binary.
Large projects split code across many .cpp and .h files built together. The source is plain text and opens in any editor; an IDE adds building and debugging.
How to open a .cpp file
The .cpp format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .cpp file.
Windows
- Visual Studio
- VS Code
- any text editor
macOS
- Xcode
- VS Code
- any text editor
Linux
- VS Code
- vim
- g++ / clang++
How to convert a .cpp file
You can convert a .cpp file to exe (via a compiler), o (object file) using a conversion tool or the export menu of an app that opens it.
.cpp file signature (magic bytes)
Programs recognise a .cpp file by the bytes at the start of the file, not by its name. These are the signatures for C++.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | plain text; no fixed magic bytes |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .cpp file?
A .cpp file is C++ source code, an extension of C that adds classes, templates and a large standard library. It is used for games, high-performance software, browsers and desktop applications.
How do I compile a .cpp file?
Use a C++ compiler: g++ file.cpp -o program then run it, or build it in Visual Studio, Xcode or VS Code.
What is the difference between C and C++?
C++ builds on C, adding classes, templates and a rich standard library while keeping C's speed. Most C code also compiles as C++.
Why are there .cpp, .cc and .cxx files?
They are all C++ source extensions; the choice is convention. Compilers treat .cpp, .cc and .cxx the same way.
Related formats
Sources
Details on this page were checked against authoritative references: