Programming foundations

Stage 6 · Lesson 4 of 7

Command-line arguments

Build and ship your first projects

A tool that others can use takes its input from the , not from paths written into the code. For example: ./ledger transactions.csv --month 2026-03. main(int argc, char* argv[]) receives these arguments.

argc is how many there are, and argv[0] holds the program name, so check argc before argv[1]. Convert them to std::string or a std::vector<std::string> straight away, and do all the parsing of options in one . When arguments are missing or invalid, print a short usage message and return a non-zero , such as 1.

Scripts and CI (automatic ) rely on exit codes to know that something failed. Libraries such as CLI11 help with many options, but for two or three arguments plain argv is enough and teaches you more.

A question to check yourself, an AI practice session and 1 cheat sheet entry come when you add the roadmap to your account. Add it

Resources for this stage

Start with

  • GitHub repoFree
    Project Based Learning

    Community maintained · Beginner

    Follow one guided build in your language, then build your own without a guide

Keep handy

  • Free APIs that give a small project real data to work with

Also worth your time

Mark this stage as not done?