How easily and quickly can you specify arguments for your program in C++



Native solution: argc and argv

int main(int argc, char* argv[]) {
for(auto i=0; i< argc; ++i) {
std::cout << argv[i] << std::endl;

Modern solution: Argh!

#include <iostream>
#include "argh.h"
int main(int, char* argv[]) {
argh::parser cmdl(argv);
if (cmdl[{ "-v", "--verbose" }])
std::cout << "Verbose, I am.\n";
float scale_factor;
cmdl({"-s", "--scale"}, 1.0f) >> scale_factor; // Use 1.0f as default value

Interesting links

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How I improved scientific data management during GSoC ‘20

Visualization and code generation of linked smart contracts as an extension of FSolidM

What’s useState hook in React

[LeetCode]#1252. Cells with Odd Values in a Matrix

Where Do I Start (learning to code)?

Launching AIM — An Open AI Development Environment

LAUNCH X431 CR-HD Pro Car/Truck Full Diangnostic Tool Scanner

Mobile robot wheel encoders with ROS2 and an ESP32 running MicroPython

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Xavier Jouvenot

Xavier Jouvenot

More from Medium

Variables in the programming languages

A Byte of Coding Issue #170

Process 101

What are dynamic libraries and how to use them in C