.CPP file extension
To open .CPP files on Windows, to view/edit: open the file in a code editor or IDE (Microsoft Visual Studio is a common choice for .cpp source files).
To open a .CPP file, use a text editor or a C++ IDE (for example, Visual Studio on Windows or a code editor on macOS/Linux). If you want to run what’s inside, you don’t “open” it—you compile it as C++ source code first.
Last updated: April 29, 2026 · Reviewed by Julian Stricker
Open on your device
Choose your operating system for a dedicated step-by-step opening guide.
How to open .CPP files
Use these platform-specific instructions to open .CPP files safely.
Windows
- To view/edit: open the file in a code editor or IDE (Microsoft Visual Studio is a common choice for .cpp source files).
- If Windows asks what to use: right-click the file → Open with → choose your editor/IDE.
- To build/compile: use your C++ toolchain (for example, Visual Studio’s build tools or GCC if installed) and compile it as C++ source.
Mac
- To view/edit: open the file in a text/code editor (any editor that can open plain text will work).
- If you need to compile: use a C++ compiler toolchain (for example, GCC, which recognizes .cpp as C++ source).
Linux
- To view/edit: open the file in a text/code editor from your file manager or terminal.
- To compile: use GCC (it recognizes .cpp and compiles it as C++ source by default) or your preferred C++ compiler toolchain.
iOS
- iOS is not a typical environment for compiling C++: open the .cpp file in a text viewer/editor app to read it, or transfer it to a desktop OS to build it.
Android
- Android is not a typical environment for compiling C++: open the .cpp file in a text viewer/editor app to read it, or transfer it to a desktop OS to build it.
Security notes
- A .cpp file is plain text, so simply viewing it in a text editor is usually low risk; the main risk comes from compiling/building it or running any program produced from it.
- Be cautious with build scripts, makefiles, or project files that may accompany a .cpp file: building a project can execute tools or commands as part of the build process.
- If you copy/paste code from an untrusted .cpp into your own project, review it carefully—source code can intentionally include unsafe behavior even though the file itself is not an executable.
Recommended antivirus software
Scan files before opening them. These antivirus tools help protect against malware and viruses.
Avast offers free and premium antivirus software that protects against viruses, malware, ransomware, and phishing. Scan files before opening them to ensure safety.
NortonNorton 360 delivers comprehensive antivirus protection, VPN, and identity theft monitoring. Scan files for threats before opening to keep your device secure.
We may earn a commission when you use affiliate links. This supports our free file extension guides.
Can't open this file?
These are the most common causes and fixes when .CPP files fail to open.
Common reasons
- Windows shows “How do you want to open this file?”
- The file opens but looks like “gibberish” or has strange characters
- Compilation fails or the build tool treats it as the wrong language
- You expected a “document,” but it’s source code
Fix steps
- Choose a text/code editor or an IDE (Visual Studio is commonly used for .cpp in C++ projects).
- Optionally set it as the default app for .cpp so future opens go directly to your chosen editor.
OS-specific troubleshooting
What is a .CPP file?
.CPP is a common filename extension for C++ source code. Tools such as GCC and Microsoft Visual Studio recognize .cpp as a main C++ source file and treat it as C++ during compilation. It is plain text (not a packaged “document” format) and typically contains program code, comments, and preprocessor directives.
Background
.cpp is widely used as the conventional extension for C++ source files. According to GCC documentation, .cpp is one of the recognized suffixes that indicates a file should be compiled as C++ source, and Visual Studio C++ projects also use .cpp for main source files.
Because .cpp is plain text, it is commonly viewed and edited in code editors and IDEs, then compiled into an executable or library as part of a build. In tooling ecosystems, .cpp is also commonly associated with the (unofficial) MIME type text/x-c++src, which is used by systems such as shared MIME-info and content detection tools.
If you received a .cpp file unexpectedly, it is most likely source code (not a “document” intended for end-users). You can read it safely as text, but compiling or building it can execute code during the build or later when you run the resulting program.
Common MIME types: text/x-c++src
Further reading
Authoritative resources for more details on the .CPP format.
Common .CPP issues
Windows shows “How do you want to open this file?”
This happens when no default app is associated with .cpp on your system.
- Choose a text/code editor or an IDE (Visual Studio is commonly used for .cpp in C++ projects).
- Optionally set it as the default app for .cpp so future opens go directly to your chosen editor.
The file opens but looks like “gibberish” or has strange characters
.cpp is plain text, but it can be saved in different encodings (or it may not actually be a C++ source file despite the extension).
- Open it in a code editor that can change text encoding and try UTF-8 (common) or other encodings if the text looks corrupted.
- If it still doesn’t look like code, treat it as mislabeled or corrupted and confirm the source of the file.
Compilation fails or the build tool treats it as the wrong language
Build failures can occur due to missing headers/libraries, incorrect compiler settings, or invoking the compiler in a way that doesn’t use C++ mode.
- If using GCC, ensure you are compiling it as C++ source (GCC recognizes .cpp as C++ by convention).
- If using Visual Studio, confirm the file is part of a C++ project and the required dependencies are present.
You expected a “document,” but it’s source code
.cpp is primarily a C++ source file extension, not a general-purpose document format.
- Open it in a code editor to read it as text; search for comments or a header describing how to use it.
- If you intended to view a formatted document, ask the sender for the correct file type (for example, PDF) rather than renaming extensions.
FAQ
Is a .CPP file the same as a C++ program?
It is C++ source code (plain text). It becomes a runnable program only after you compile it with a C++ compiler and then run the resulting executable.
What MIME type is used for .cpp files?
Many systems use the unofficial MIME type text/x-c++src for C++ source. It is commonly used in tooling and shared MIME databases, but it is not an IANA-registered “official” media type.
Can I convert a .cpp file by renaming it?
No. Renaming only changes the filename extension. If you need a different format, you must use an appropriate tool or export process (for example, generating documentation or copying code into another file type).
Why does my compiler recognize .cpp automatically?
Compilers and build systems commonly use the file suffix to determine language mode. For example, GCC documentation notes that .cpp is a conventional suffix that is recognized and compiled as C++.
Similar file extensions
Compare related formats in the same category to find the right tool faster.