Code Monkey home page Code Monkey logo

dr_opt's Introduction

dr_opt

A simple C++ getopt component


Description


dr_opt is a command options parser (similar to the most basic functionality of getopt.h) that I can use between multiple platforms. argc and args must be provided to setopt before using the other functions.

Functions

void setopt(int argc, char* args[]);
Used to format all incoming command line option data.

bool hasopt(const std::string& flag);
Used for checking if an option was provided on the command line.

const std::string& getopt(const std::string& flag);
If an option is accompanied by a string parameter, then that parameter is returned. Returns "" otherwise.

Getting Started


Test Limitations

  • premake5
  • batch and bash scripts create vs2019 (Solution) and gmake2 (Makefile) files respectfully

Installing

  • Copy the dr_opt header and source file (not test.cpp) into a project

Example


#include <iostream>
#include <string>

#include "dr_opt.h"

int main(int argc, char* args[]) {
    dr::setopt(argc, args);

    // You can also use flags more than one character in length
    if(dr::hasopt("a")) {
        // "-a" flag was found in command options
        std::string aOpt = dr::getopt("a");
        // "aOpt" now contains the "-a" flag parameter
        std::cout << aOpt << std::endl;
    }

    return 0;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.