Stage 6 · Lesson 4 of 7
Command-line arguments
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 repoFreeProject Based Learning
Community maintained · Beginner
Follow one guided build in your language, then build your own without a guide
Keep handy
Also worth your time
How to present each project: the problem, stack, challenges and results
- Build Your Own XGo deeper
When you want a harder build: a shell, a key-value store or a tiny Git, from scratch