Skip to content

Instantly share code, notes, and snippets.

@philtomson
Created September 15, 2012 17:02
Show Gist options
  • Save philtomson/3728841 to your computer and use it in GitHub Desktop.
Save philtomson/3728841 to your computer and use it in GitHub Desktop.
Using boost::program_options
//To compile:
//g++ -I /usr/include/boost -o op_parser op_parser.cpp /usr/lib64/libboost_program_options-mt.a
#include <iostream>
#include "boost/program_options.hpp"
namespace po = boost::program_options;
using namespace std;
int main(int argc, char** argv){
string list_file;
string verilog_file;
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("list_file", po::value<string>(), "list file to read")
("v", po::value<string>(), "single verilog file")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if(vm.count("help")) {
cout << desc << "\n";
return 1;
}
if(vm.count("list_file")) {
list_file = vm["list_file"].as<string>();
cout << "list file is: " << list_file << ".\n";
} else {
cout << "list_file was not set.\n";
}
if(vm.count("v")){
verilog_file = vm["v"].as<string>();
cout << "verilog file is: " << verilog_file << ".\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment