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.
What opens 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.
Windows
- Visual Studio
- VS Code
- any text editor
macOS
- Xcode
- VS Code
- any text editor
Linux
- VS Code
- vim
- g++ / clang++
Open a .cpp file step by step
- Confirm the file really is a .cpp. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
- On Windows, open it with Visual Studio or VS Code.
- On Mac, use Xcode or VS Code.
- On Linux, try VS Code or vim.
- Still stuck? Convert the .cpp to exe (via a compiler), which opens more widely.
Why can't I open my .cpp file?
Almost always because no installed app understands C++. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.
The other possibility is that the file is not really a .cpp at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.
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.
C++ has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.
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. How sources are ranked and what is deliberately left out is set out in the methodology.