What is a CPP File?
A CPP file is a plain-text source code file written in C++, the language Bjarne Stroustrup created as an extension of C. C++ adds classes, templates and a large standard library. CPP files usually hold the program logic, while declarations go into header files (.H or .HPP).
Like C code, C++ has to be compiled before it can run: a compiler such as GCC (g++), Clang or Microsoft Visual C++ turns CPP files into an executable program. C++ is used for performance-critical software, including Google Chrome, Mozilla Firefox, MySQL and Adobe Photoshop.
Download CPP Sample Files
The three samples below are small, complete console programs. Each one compiles on its own with any modern C++ compiler and reads a number from standard input, which makes them handy for testing compilers, build pipelines, code editors and online judges.
CPP Sample File Details
| Sample | What it does | Lines | Size | Example input → output |
|---|---|---|---|---|
| Sample1.CPP | Checks whether an integer is even or odd | 16 | 226 bytes | 7 → “7 is odd.” |
| Sample2.CPP | Reverses the digits of an integer | 19 | 343 bytes | 12345 → “Reversed Number = 54321” |
| Sample3.CPP | Checks whether a number is prime, using a separate function | 36 | 575 bytes | 29 → “29 is a prime number.” |
All three files are ASCII text with Windows (CRLF) line endings and only use <iostream>. They compile without warnings with g++ -std=c++17 -Wall -Wextra (tested with GCC 11).
What You Can Test With These CPP Files
- Compilers and builds: GCC, Clang, MSVC, CMake projects and CI jobs.
- Editors and IDEs: syntax highlighting, formatting and language-server features.
- Online judges and code runners: programs that read their input from stdin.
- Uploads and previews: features that should treat .cpp as text (MIME type
text/x-c++src). - Line endings: the files use CRLF, a common source of problems in Git and Linux tools.
How to Compile and Run a CPP File
# Linux or macOS (GCC or Clang)
g++ -std=c++17 -Wall sample-1.cpp -o sample-1
./sample-1
# Windows (Developer Command Prompt for Visual Studio)
cl /EHsc sample-1.cpp
sample-1.exe
To run a sample without typing, send the input through a pipe, for example echo 12345 | ./sample-2.






