.CPP

CPP File

C++ Source Code File
Ask a question
QUICK ANSWER

A CPP file is plain-text C++ source code - the human-written instructions that a compiler turns into a runnable program. Open it in any code editor (VS Code, Notepad++, Xcode) to read or edit the code. To run it, compile it first with GCC, Clang, or MSVC: the file does nothing on its own.

Developer: Bjarne Stroustrup / Bell Labs (C++ language); standardized by ISO/IEC Category: Developer Files Open standard MIME: text/x-c++src
OPENS ON Windows macOS Linux
Related: .DO · .MD · .HEX · .XSD

On this page

19k+ extensions indexed
Last reviewed Sep 7, 2026

Not sure what your file is?

Drop any file into our identifier - we read just the first bytes to name the format.

Identify a file

What is the CPP file format?

.cpp files contain source code written in C++, a general-purpose programming language created by Bjarne Stroustrup at Bell Labs in the early 1980s. The .cpp extension stands for "C plus plus" - alternative conventions such as .cc and .cxx denote the same kind of source file under different toolchain traditions.

Contents of .cpp files

Files with a .cpp extension can contain such elements as:

  • variable and type declarations,
  • function declarations and definitions,
  • class declarations and member-function implementations,
  • preprocessor directives (e.g. #include <iostream>, #define),
  • references to system libraries and .h or .hpp header files,
  • comments for better code legibility - these are omitted during compilation.

Is a .cpp file a program?

.cpp files contain program source code written in C++, but in order to run such applications the source code must be compiled. A compiler - such as g++, clang++, or MSVC - takes the source code and translates it into machine code the computer can execute directly. Only the compiled output can be called a program; the .cpp file itself is just text. A project typically compiles multiple .cpp files and links them together to produce a final executable.

Can I open a .cpp file?

.cpp files are nothing more than plain text files and can be edited using any text editor. However, editing them requires knowledge of C++ syntax to avoid errors that may prevent compilation or cause the program to run incorrectly. For this reason, editing .cpp files is best done using dedicated tools that offer helpful features such as:

  • automated line numbering,
  • syntax highlighting,
  • code completion and hints,
  • syntax error notifications (missing closing brackets, semicolons, etc.),
  • integrated build and debugger support.

Popular environments include Microsoft Visual Studio, VS Code, and Apple Xcode. The .cpp file itself carries no embedded version information - the target C++ standard (from C++98 through C++23) is chosen at compile time via compiler flags.

Security & safety

RISK: LOW

A .cpp file is plain text and cannot run on its own, so opening one in an editor is safe. The risk appears only when you COMPILE and RUN unknown C++ code: source from an untrusted origin can do anything a program can once built (delete files, network access, install malware), and C++'s low-level access makes malicious or buggy code easy to hide. Read code before compiling it, build untrusted code in a sandbox/VM, and never run a compiled binary you don't trust. The file extension itself carries no exploit - the danger is in what the code does after compilation.

Format details

in a nutshell
FULL NAMEC++ Source Code Fileaka C plus plus source file, C++ implementation file
DEVELOPERBjarne Stroustrup / Bell Labs (C++ language); standardized by ISO/IECsince C++ language created 1979-1985 (Bjarne Stroustrup, Bell Labs); first ISO standard C++98 (1998)
MIME TYPEtext/x-c++src
TYPEPlain-text programming source code (C++ language)
STANDARDOpen · royalty-free
This extension is also used by…
  • C++ source (alternate extensions) - The same C++ source role is also carried by .cc, .cxx, .c++ and (uppercase) .C; .cpp is the dominant Windows/cross-platform convention.

Programs that open CPP files

Windows5 apps
Microsoft Visual Studio Freemium Open or add the .cpp to a C++ project and press Build/Run; the free Community edition includes the MSVC compiler.
Code::Blocks Open-source Free cross-platform C++ IDE bundling MinGW; open the .cpp and press Build & Run.
Notepad Open-source Open the .cpp to read/edit with C++ syntax highlighting (viewing/editing only - no compiler).
Visual Studio Code Free Open the .cpp for syntax-highlighted editing; add the C/C++ extension + a compiler (MSVC or MinGW g++) to build and debug.
MinGW-w64 / GCC (g++) Open-source Command line: 'g++ hello.cpp -o hello.exe' then run hello.exe. The standard free Windows C++ compiler.
macOS2 apps
Apple Xcode (Apple Clang) Free Open in Xcode, or use the bundled clang++ from Terminal: 'clang++ hello.cpp -o hello && ./hello'.
Visual Studio Code Free Edit the .cpp with the C/C++ extension; compile with the clang++ command-line tools installed via Xcode.
Linux3 apps
GCC / g++ (GNU Compiler Collection) Open-source Compile from a terminal: 'g++ hello.cpp -o hello && ./hello'. Pre-installed or one package away on every distro.
GNU Emacs / Vim Open-source Open the .cpp in the terminal editor to read/edit with C++ highlighting; pair with g++/make to build.
Visual Studio Code Free Cross-platform editor with the C/C++ extension; edits, builds (via g++/clang++) and debugs .cpp files.

Technical details

deep spec
MIME typetext/x-c++src (also accepted: text/x-c++ and text/plain)
File encodingPlain text - ASCII or UTF-8; a UTF-8 BOM (EF BB BF) at offset 0 is accepted but not required
File signature / magic bytesNone - identified by content: typically opens with // or /* */ comments, #include directives, or class/function definitions
File structurePreprocessor directives (#include, #define, #if), using/namespace declarations, class and function definitions, and the main() entry point
Compilation requiredYes - must be compiled by g++, clang++, or MSVC; the .cpp file is human-readable source text, not an executable
Target language standardsC++98, C++03, C++11, C++14, C++17, C++20, C++23; the standard is selected via a compiler flag (e.g., -std=c++17) and is not stored inside the file
Preprocessor stageBefore compilation, the C preprocessor expands #include directives, #define macros, and conditional-compilation blocks (#if / #endif)
Companion file types.h and .hpp (header declarations), .cc and .cxx (alternative C++ source extensions), .o / .obj (compiled object file output)
Compilation outputAn object file (.o on Linux/macOS, .obj on Windows) that the linker combines with other objects into an executable or shared library
Typical file sizeA few KB to tens of KB per source file; machine-generated or heavily templated files may exceed 1 MB
Unicode / character supportString literals and identifiers support Unicode (UTF-8) from C++11 onward; u8, u, and U string prefix literals allow explicit encoding control
Line endingsPlatform-independent - LF (Unix/macOS), CRLF (Windows), and CR are all accepted by major compilers
Associated operating systemsWindows, macOS, Linux - and any platform with a conforming C++ compiler toolchain
Standards bodyISO/IEC JTC1/SC22/WG21 (the C++ Standards Committee); standards are published as ISO/IEC 14882 revisions on roughly a 3-year cycle
File naming conventionTypically matches the class or module it implements - e.g., MyClass.cpp paired with MyClass.h or MyClass.hpp
Extension name meaningThe letters "pp" stand for "plus plus"; identical C++ source content may alternatively use .cc or .cxx by toolchain convention
ReleasedC++ language created 1979-1985 (Bjarne Stroustrup, Bell Labs); first ISO standard C++98 (1998)
Latest versionISO/IEC 14882:2024 (C++23); C++26 in progress
Open standardYes · royalty-free
Specificationisocpp.org

CPP conversions

Community Q&A

asked by users
Ask a quick question
Get help from people who work with CPP files. Be specific - include your system and software version.
No account needed · answers usually within a day

No questions yet - be the first to ask about CPP files.

Frequently asked questions

How do I open a .cpp file?
To read or edit it, open it in any text editor - Notepad++, VS Code, Vim or Xcode give C++ syntax highlighting. It's just text, so even Notepad works for a quick look.
How do I compile and run a .cpp file?
Install a C++ compiler and run it on the file. On Windows: 'g++ hello.cpp -o hello.exe' (MinGW) then run hello.exe, or build in Visual Studio. On macOS/Linux: 'g++ hello.cpp -o hello && ./hello'.
How do I turn a .cpp file into an .exe?
You compile it, not convert it. With GCC: 'g++ program.cpp -o program.exe'. In Visual Studio, add the .cpp to a project and press Build - the .exe is the compiler's output.
What's the difference between a .cpp and a .h file?
A .cpp file holds the implementation (the actual code); a .h/.hpp header holds declarations (prototypes, class/type definitions, macros) shared across .cpp files via #include. You compile .cpp files, not headers.
What is the difference between .cpp, .cc and .cxx?
All three are C++ source files - compilers treat them identically. .cpp is the common Windows/cross-platform choice; .cc and .cxx are conventions favoured by some Unix and Google-style projects. The extension is a style choice.
Is .cpp the same as .c?
No. .c is C source; .cpp is C++ source. Most C compiles as C++, but C++ adds classes, templates and namespaces that a C compiler can't handle. Compilers pick the language from the extension.

References

1GCC - GNU Compiler Collection (official)gcc.gnu.org
2ISO C++ - The C++ standard (isocpp.org)isocpp.org

Keep exploring

across the database

Top extensions this week

1.AQQAQQ Instant Messenger File
2.MDMarkdown Document
3.CRDOWNLOADChrome Partial Download File
4.BINCD/DVD Disc Image (BIN/CUE)
5.PARTPartial Download File
6.RPMSGRestricted Permission Message
7.NOMEDIAAndroid No-Media Marker File
8.EXEWindows Executable (Portable Executable)
9.AVIFAV1 Image File Format (AVIF)
10.ICSiCalendar data file

Related extensions

.DOStata Do-File
.MDMarkdown Document
.HEXIntel HEX File
.XSDXML Schema Definition
.MAPSource Map (JavaScript / CSS)
.CONFIGConfiguration File

Free file tools

An in-browser file identifier and image converter - everything runs on your device.

Open the toolbox

Browse file extensions A-Z