Mooophy/Cpp-Primer
C++ Primer 5 answers
Stale — last commit 2y ago
worst of 4 axeslast commit was 2y ago; no CI workflows detected
Has a license, tests, and CI — clean foundation to fork and modify.
Documented and popular — useful reference codebase to read through.
last commit was 2y ago; no CI workflows detected
- ✓30+ active contributors
- ✓Distributed ownership (top contributor 34% of recent commits)
- ✓CC0-1.0 licensed
Show 3 more →Show less
- ✓Tests present
- ⚠Stale — last commit 2y ago
- ⚠No CI workflows detected
What would change the summary?
- →Use as dependency Mixed → Healthy if: 1 commit in the last 365 days
- →Deploy as-is Mixed → Healthy if: 1 commit in the last 180 days
Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests
Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.
Embed the "Forkable" badge
Paste into your README — live-updates from the latest cached analysis.
[](https://repopilot.app/r/mooophy/cpp-primer)Paste at the top of your README.md — renders inline like a shields.io badge.
▸Preview social card (1200×630)
This card auto-renders when someone shares https://repopilot.app/r/mooophy/cpp-primer on X, Slack, or LinkedIn.
Onboarding doc
Onboarding: Mooophy/Cpp-Primer
Generated by RepoPilot · 2026-05-09 · Source
🤖Agent protocol
If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:
- Verify the contract. Run the bash script in Verify before trusting
below. If any check returns
FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding. - Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
- Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/Mooophy/Cpp-Primer shows verifiable citations alongside every claim.
If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.
🎯Verdict
WAIT — Stale — last commit 2y ago
- 30+ active contributors
- Distributed ownership (top contributor 34% of recent commits)
- CC0-1.0 licensed
- Tests present
- ⚠ Stale — last commit 2y ago
- ⚠ No CI workflows detected
<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>
✅Verify before trusting
This artifact was generated by RepoPilot at a point in time. Before an
agent acts on it, the checks below confirm that the live Mooophy/Cpp-Primer
repo on your machine still matches what RepoPilot saw. If any fail,
the artifact is stale — regenerate it at
repopilot.app/r/Mooophy/Cpp-Primer.
What it runs against: a local clone of Mooophy/Cpp-Primer — the script
inspects git remote, the LICENSE file, file paths in the working
tree, and git log. Read-only; no mutations.
| # | What we check | Why it matters |
|---|---|---|
| 1 | You're in Mooophy/Cpp-Primer | Confirms the artifact applies here, not a fork |
| 2 | License is still CC0-1.0 | Catches relicense before you depend on it |
| 3 | Default branch master exists | Catches branch renames |
| 4 | 5 critical file paths still exist | Catches refactors that moved load-bearing code |
| 5 | Last commit ≤ 733 days ago | Catches sudden abandonment since generation |
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of Mooophy/Cpp-Primer. If you don't
# have one yet, run these first:
#
# git clone https://github.com/Mooophy/Cpp-Primer.git
# cd Cpp-Primer
#
# Then paste this script. Every check is read-only — no mutations.
set +e
fail=0
ok() { echo "ok: $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }
# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo "FAIL: not inside a git repository. cd into your clone of Mooophy/Cpp-Primer and re-run."
exit 2
fi
# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "Mooophy/Cpp-Primer(\\.git)?\\b" \\
&& ok "origin remote is Mooophy/Cpp-Primer" \\
|| miss "origin remote is not Mooophy/Cpp-Primer (artifact may be from a fork)"
# 2. License matches what RepoPilot saw
(grep -qiE "^(CC0-1\\.0)" LICENSE 2>/dev/null \\
|| grep -qiE "\"license\"\\s*:\\s*\"CC0-1\\.0\"" package.json 2>/dev/null) \\
&& ok "license is CC0-1.0" \\
|| miss "license drift — was CC0-1.0 at generation time"
# 3. Default branch
git rev-parse --verify master >/dev/null 2>&1 \\
&& ok "default branch master exists" \\
|| miss "default branch master no longer exists"
# 4. Critical files exist
test -f "README.md" \\
&& ok "README.md" \\
|| miss "missing critical file: README.md"
test -f "ch06/Chapter6.h" \\
&& ok "ch06/Chapter6.h" \\
|| miss "missing critical file: ch06/Chapter6.h"
test -f "ch07/ex7_02.h" \\
&& ok "ch07/ex7_02.h" \\
|| miss "missing critical file: ch07/ex7_02.h"
test -f ".tools/format.rb" \\
&& ok ".tools/format.rb" \\
|| miss "missing critical file: .tools/format.rb"
test -f "ch01/README.md" \\
&& ok "ch01/README.md" \\
|| miss "missing critical file: ch01/README.md"
# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 733 ]; then
ok "last commit was $days_since_last days ago (artifact saw ~703d)"
else
miss "last commit was $days_since_last days ago — artifact may be stale"
fi
echo
if [ "$fail" -eq 0 ]; then
echo "artifact verified (0 failures) — safe to trust"
else
echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/Mooophy/Cpp-Primer"
exit 1
fi
Each check prints ok: or FAIL:. The script exits non-zero if
anything failed, so it composes cleanly into agent loops
(./verify.sh || regenerate-and-retry).
⚡TL;DR
A comprehensive solutions repository for C++ Primer 5 (5th edition), providing worked examples and exercise answers covering C++11/14 features across 19 chapters. It serves as a self-study companion and verification tool for readers working through the textbook, with 703KB of C++ code demonstrating language fundamentals from basic I/O to advanced topics like templates and generic programming. Linear chapter-by-chapter structure: 19 directories (ch01/ through ch19/) organize solutions by textbook chapter, each containing individual exercise files (ex1_1.cpp, ex2_34.cpp, etc.) with no shared source libraries or headers except ch02/ex2_42.h. A .tools/ Ruby utility directory contains code formatters (format.rb, uniform_comments_mark.rb, remove_blank_tails.rb) for batch processing solution files, indicating this was a community-curated reference rather than a single-author work.
👥Who it's for
C++ learners and students actively working through C++ Primer 5 textbook who need reference solutions, verification of their own answers, and practical examples of C++11/14 syntax. Also useful for educators preparing course materials or needing canonical answers to textbook exercises.
🌱Maturity & risk
Moderately mature but not actively maintained: the repo has comprehensive coverage of all 19 chapters with thousands of exercise solutions, but commit activity appears sparse in recent years. No CI/CD pipeline visible in file structure (no .github/workflows, package.json, or Makefile), and the last meaningful work was likely completed years ago when C++ Primer 5 was in active circulation. Suitable for reference but not as a living, evolving resource.
Low risk for learning purposes but requires care: the code targets C++11/14 via g++ 5.0+, clang++ 3.7+, or Visual Studio 2015+ (all now legacy), so modern compiler compatibility is unverified. No test suite exists to validate solutions (see absence of test/ or catch/gtest directories), creating risk that solutions contain subtle errors. Single-maintainer (Mooophy) with no recent activity means issues and PRs are unlikely to be addressed.
Active areas of work
No active development visible. The repo appears complete relative to the C++ Primer 5 textbook scope and shows no ongoing work, open PRs, or issue triage. It functions as a static reference snapshot frozen at a point when C++11/14 were the focus; no migration to C++17/20 features or modernization is planned.
🚀Get running
git clone https://github.com/Mooophy/Cpp-Primer.git
cd Cpp-Primer
g++ -std=c++14 ch01/ex1_1.cpp -o ch01/ex1_1
./ch01/ex1_1
On Linux use g++ -std=c++14, on Mac use clang++ -std=c++1y, on Windows use Visual Studio 2015+ project import.
Daily commands:
Compile individual exercise files directly: g++ -std=c++14 chXX/exX_Y.cpp -o exX_Y && ./exX_Y. Some exercises may require user input via stdin. Multi-file exercises (like ex2_42_1.cpp, ex2_42_2.cpp, ex2_42_3.cpp) share a header (ex2_42.h) and must be compiled together or linked explicitly.
🗺️Map of the codebase
README.md— Entry point documenting the entire C++ Primer 5 exercise collection, compiler requirements, and chapter structure that every contributor must reference.ch06/Chapter6.h— Core header file for Chapter 6 (Functions) containing reusable function declarations and definitions that multiple exercises depend on.ch07/ex7_02.h— Header file for Chapter 7 (Classes) establishing class definition patterns and conventions used across multiple class-based exercises..tools/format.rb— Build/format tool used to maintain consistent code style and formatting across the entire codebase.ch01/README.md— Chapter 1 guide that establishes the foundational patterns and documentation standards followed by all subsequent chapters.ch06/fact.cc— Example implementation demonstrating separate compilation and linking patterns used throughout multi-file exercises.
🧩Components & responsibilities
- Exercise Source Files (.cpp) (C++11/14, Standard Library (iostream, string, vector, algorithm, etc.)) — Implement C++ Primer exercise solutions with complete, runnable code demonstrating learned concepts
- Failure mode: Compilation errors or runtime failures indicate misunderstanding of C++ semantics; output mismatch suggests logic error
- Header Files (.h) (C++ preprocessor directives, class syntax, forward declarations) — Define class/function interfaces and demonstrate proper header organization; used in multi-file exercises
- Failure mode: Missing include guards or redefinition errors; indicates improper header structure
- Chapter README Files (Markdown documentation) — Document exercise organization, key concepts covered, and provide navigation for learners
- Failure mode: Outdated or missing READMEs create confusion about exercise scope and prerequisites
- Build & Formatting Tools (.tools/) (Ruby scripting, regex-based text processing) — Maintain consistent code style and facilitate bulk formatting operations across repository
- Failure mode: Broken formatting scripts cause inconsistent code style; may corrupt source files if run incorrectly
🛠️How to make changes
Add a new exercise solution
- Create a new .cpp file in the appropriate chapter directory (e.g., ch03/ex3_XX.cpp for Chapter 3) (
ch03/ex3_1a.cpp) - Include necessary standard library headers and follow the naming convention exN_M.cpp where N is chapter and M is exercise number (
ch05/ex5_5.cpp) - Implement the exercise with comments explaining the learning objective from C++ Primer (
ch06/ex6_10.cpp) - Compile with recommended compiler flags: g++ -std=c++14 or clang++ -std=c++1y (
README.md)
Add a multi-file function exercise (like Chapter 6)
- Create a header file with function declarations (e.g., Chapter6.h) (
ch06/Chapter6.h) - Create implementation file(s) with .cc extension (e.g., fact.cc for factorial function) (
ch06/fact.cc) - Create a main driver file (e.g., factMain.cc) that calls the functions (
ch06/factMain.cc) - Compile all files together: g++ -std=c++14 fact.cc factMain.cc -o factMain (
README.md)
Add a class definition exercise (like Chapter 7)
- Create a header file with class declaration (e.g., ex7_02.h following naming convention) (
ch07/ex7_02.h) - Include member variables, constructors, and public/private member functions (
ch07/ex7_04.h) - Create a .cpp file to demonstrate class usage with a main() function (
ch07/ex7_01.cpp) - Compile and test: g++ -std=c++14 ex7_XX.cpp -o ex7_XX (
README.md)
Maintain code style consistency
- Run the format.rb script from .tools directory to standardize code formatting (
.tools/format.rb) - Use insert_space_in_include.rb to ensure consistent #include spacing (
.tools/insert_space_in_include.rb) - Apply remove_blank_tails.rb to eliminate trailing whitespace (
.tools/remove_blank_tails.rb)
🔧Why these technologies
- C++11/14 Standard — Matches C++ Primer 5 edition which is built on C++11/14 features; compiler recommendations ensure modern language support.
- Ruby Build Tools (.tools) — Lightweight scripting for formatting and maintenance automation without heavyweight build systems; appropriate for educational codebase.
- Header Files (.h) for Declarations — Demonstrates proper separation of interface and implementation, a core C++ pattern taught in Chapter 6 and beyond.
⚖️Trade-offs already made
-
Use separate .cc and .h files for multi-file exercises
- Why: Teaches compilation model, linking, and forward declarations as emphasized in Chapter 6
- Consequence: Requires manual compilation of multiple files; students must understand compiler/linker stages
-
Store all solutions in single-exercise-per-file format
- Why: Simplicity and clarity; each file maps directly to one C++ Primer exercise
- Consequence: Large number of small files (600+ total); does not scale well to production patterns like libraries or modules
-
No automated test framework
- Why: Educational focus on manual verification and understanding; keeps setup lightweight for learners
- Consequence: Relies on developer to verify correctness against textbook; no regression testing
-
No CMake or Make build system
- Why: Beginners should learn compiler invocation directly before abstraction layers
- Consequence: Manual g++/clang++ commands required; doesn't scale to complex multi-target builds
🚫Non-goals (don't propose these)
- Not a production C++ library or framework; purely educational exercise solutions
- Does not provide pre-compiled binaries; students compile from source as a learning step
- Not an alternative to C++ Primer textbook; complements it by providing reference solutions
- Does not cover advanced topics beyond C++14 standard (e.g., C++17/20 features)
- Not designed for Windows-only environments; supports cross-platform compilation (Linux, Mac, Windows with compatible compilers)
🪤Traps & gotchas
No hidden traps in the traditional sense, but be aware: (1) Code targets C++11/14; if you compile with C++17+ (-std=c++17), some deprecated features may trigger warnings or errors depending on compiler strictness. (2) Some exercises expect interactive input (stdin) and will hang if not provided; test exercises that call cin before assuming they're broken. (3) The .tools/ Ruby scripts assume Ruby is installed and paths are Unix-like; they won't work on Windows without adaptation. (4) Multi-file exercises like ex2_42 require coordinated compilation (link all .cpp files or manually link the .o files) or they'll have missing symbol errors.
🏗️Architecture
💡Concepts to learn
- std::vector and dynamic arrays — Core topic in ch03/; mastering vector's growth mechanics (capacity vs. size) and iterator invalidation is critical for safe C++ programming
- Move semantics and rvalue references (&&) — Central to C++11; enables efficient ownership transfer in containers and classes; solutions in ch13 (Copy Control) demonstrate move constructors and move assignment operators
- Template specialization and generic programming — ch16 exercises require understanding function templates, class templates, and template specialization; foundational for writing reusable, type-safe C++ code
- Memory management with smart pointers (unique_ptr, shared_ptr) — ch12 (Dynamic Memory) solutions demonstrate RAII and smart pointer ownership semantics; critical for preventing memory leaks in modern C++
- Lambda expressions and function objects — C++11 feature used extensively in ch10 (Generic Algorithms) for predicates and comparators; essential for functional-style C++ programming
- Object-Oriented Programming: inheritance, virtual functions, polymorphism — ch15 (OOP) solutions demonstrate class hierarchies, virtual method dispatch, and abstract base classes; critical for understanding C++'s type system
- Operator overloading and user-defined conversions — ch14 exercises require defining operators (+, <<, ==, etc.) and conversion operators; enables intuitive APIs and domain-specific syntax
🔗Related repos
AnthonyCalandra/modern-cpp-features— Complements this repo by documenting C++11/14/17/20 feature syntax and capabilities in a reference format, useful for understanding why solutions use specific idiomsisocpp/CppCoreGuidelines— Official C++ best practices and style guidance; solutions in this repo sometimes predate these guidelines, so readers should cross-reference for modern idiomatic C++jwakely/cxx-stdlib— Deep dive into C++ standard library implementation details; useful for understanding how vector, string, and algorithm implementations work under the hood in the exercisescppreference/cppreference-doc— Canonical C++ standard library documentation; essential companion for looking up function signatures and behavior used in the exercise solutionsMooophy/Cpp-Primer-Practices— Companion repo by same author with additional practice problems and extended discussions not covered in the textbook, extending this repo's scope
🪄PR ideas
To work on one of these in Claude Code or Cursor, paste:
Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.
Add missing Chapter README files and complete exercise listings
The repo has chapters ch01-ch05 with README.md files, but the file structure shows incomplete exercise coverage. Many chapter exercises are missing (e.g., ch01 is missing ex1_2-ex1_8, ex1_12-ex1_15, etc.). Adding comprehensive README.md files for each chapter with complete exercise listings and status markers would help contributors identify exactly which exercises need solutions. This is especially valuable since the repo appears to be a reference for C++ Primer 5 exercises.
- [ ] Audit ch01/README.md through ch05/README.md to list all exercises from C++ Primer 5
- [ ] Create a status matrix showing which exercises have implementations (use ✓/✗ or similar)
- [ ] Add links from README entries to corresponding .cpp files
- [ ] Document any exercises intentionally skipped with reasoning in chapter READEMs
- [ ] Consider adding a root-level PROGRESS.md tracking completion percentage per chapter
Create automated build validation for all .cpp files
The repo contains 50+ C++ source files across chapters, but there's no mechanism to verify they compile with the recommended compilers (g++ 5.0+, clang++ 3.7+, Visual Studio 2015+). Add a GitHub Actions workflow to compile all exercises and catch compilation failures. This prevents regressions when code is updated and gives confidence to users following the solutions.
- [ ] Create .github/workflows/compile.yml with matrix strategy for g++, clang++, MSVC
- [ ] Configure workflow to compile all ch*/ex*.cpp files with -std=c++14 flag
- [ ] Add workflow status badge to root README.md
- [ ] Document compilation expectations in ch01/README.md as baseline
- [ ] Consider adding a .gitignore entry for compiled binaries if not already present
Add exercise difficulty/topic metadata and searchability
Currently, exercises are named only by chapter and number (ex1_1.cpp, ex3_45.cpp, etc.), making it hard for learners to find exercises on specific topics (e.g., all vector exercises, all pointer exercises). Create a structured metadata file or add comments to each exercise file indicating its primary topic, difficulty level, and related C++ Primer sections. This improves discoverability significantly.
- [ ] Create exercises_index.json or EXERCISE_GUIDE.md with structure: {chapter, exercise_number, topic, difficulty, relevant_sections}
- [ ] Audit all existing files (ch01-ch05) and add header comments with topic tags (e.g., /* Topic: input/output, control flow */)
- [ ] Generate a searchable index in README (or link to EXERCISE_GUIDE.md) organized by topic
- [ ] Add examples like 'Exercises on std::vector: ch03/ex3_5a.cpp, ch03/ex3_10.cpp' for quick reference
🌿Good first issues
- Add compiler compatibility verification: create a .github/workflows/ci.yml that tests each chapter's solutions against g++ 5.0+ and clang++ 3.7+ (currently no CI exists, and no guarantee solutions compile cleanly on all target platforms).
- Document missing exercises: chapters ch04 through ch19 lack README.md files explaining which textbook exercises are covered by which .cpp files (ch01, ch02, ch03 have them, but ch04/, ch05/, etc. do not).
- Modernize to C++17: add .cpp17/ parallel directory with refactored solutions using C++17 features (structured bindings, std::optional, if constexpr, etc.) to keep repo relevant for modern learners.
⭐Top contributors
Click to expand
Top contributors
- [@pezy chen](https://github.com/pezy chen) — 34 commits
- @pezy — 17 commits
- @Hierom — 10 commits
- @iamvickynguyen — 4 commits
- @smzztx — 4 commits
📝Recent commits
Click to expand
Recent commits
09bbce2— Merge pull request #763 from q1uyj/ex1-11 (pezy)abcb44b— Merge pull request #841 from amacleod1417/master (pezy)b02df4e— Fixed spelling and syntax errors, added functions to fix accumulate algorithm: Ally MacLeod (Ally MacLeod)c1d53eb— Merge pull request #839 from iamvickynguyen/vicky-ex6-55-func-pointer (pezy)0321950— add functions to vector (iamvickynguyen)a38ec3c— Merge pull request #838 from iamvickynguyen/vicky-ex6-36-reference (pezy)3e3797f— remove parameters in ex6.37 (iamvickynguyen)623ac17— remove parameter (iamvickynguyen)039f7d4— Merge pull request #837 from iamvickynguyen/vicky-ex6-18-declarations (pezy)311eaba— add const and reference (iamvickynguyen)
🔒Security observations
This is an educational repository containing C++ Primer 5 exercise answers with minimal security risk. The codebase consists of C++ source files and Ruby utility scripts with no production deployment artifacts, dependencies, database connections, or user input handling. No hardcoded credentials, API keys, or sensitive data were identified. The main recommendations are administrative: establishing a security policy, managing build tool dependencies, and adding security best practices documentation. The low overall risk profile is appropriate for an educational resource, though best practices around build tool management should be implemented.
- Low · No Security Policy or Guidelines —
Repository root. The repository lacks a SECURITY.md file or security policy documentation. This makes it unclear how security vulnerabilities should be reported or handled. Fix: Create a SECURITY.md file with vulnerability disclosure guidelines and contact information for security reports. - Low · Ruby Build Tools Without Dependency Lock —
.tools/. The .tools directory contains Ruby scripts (.tools/dir_handler.rb, .tools/format.rb, etc.) but no Gemfile.lock or dependency management is visible. This could lead to unpredictable behavior if dependencies are updated. Fix: Add a Gemfile with pinned versions and Gemfile.lock to manage Ruby script dependencies consistently. - Low · Missing Input Validation Documentation —
README.md, Example files. As an educational repository containing C++ code examples, there is no documentation about secure coding practices or input validation patterns that should be followed in the examples. Fix: Add security best practices section to README.md highlighting input validation, buffer overflow prevention, and other C++ security considerations.
LLM-derived; treat as a starting point, not a security audit.
👉Where to read next
- Open issues — current backlog
- Recent PRs — what's actively shipping
- Source on GitHub
Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.